vb.net 教程 5-13 图像处理之像素处理 8-3

前端之家收集整理的这篇文章主要介绍了vb.net 教程 5-13 图像处理之像素处理 8-3前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
之前两节都是保留的单一色系,这次我们要尝试保留多个色系。
还是先看看运行效果,保留绿、蓝、紫、黄这几个色系颜色:
有了上两节的基础,这次很容易理解。
    '自定义
    Private Sub Button13_Click(sender As Object,e As EventArgs) Handles Button13.Click
        Dim pSourceColor As Color
        Dim pDestColor As Color
        Dim destImg As New Bitmap(sourceImg.Width,sourceImg.Height)

        For i As Integer = 0 To sourceImg.Width - 1
            For j As Integer = 0 To sourceImg.Height - 1
                pSourceColor = sourceImg.GetPixel(i,j)
                Select Case getSingleColor(pSourceColor)
                    Case "R"
                        If cbR.Checked = True Then
                            If cbStrong.Checked = True Then
                                pDestColor = Color.FromArgb(pSourceColor.R,0)
                            Else
                                pDestColor = pSourceColor
                            End If
                        Else
                            pDestColor = getAverage(pSourceColor)
                        End If
                    Case "G"
                        If CBG.Checked = True Then
                            If cbStrong.Checked = True Then
                                pDestColor = Color.FromArgb(0,pSourceColor.G,0)
                            Else
                                pDestColor = pSourceColor
                            End If
                        Else
                            pDestColor = getAverage(pSourceColor)
                        End If
                    Case "B"
                        If cbB.Checked = True Then
                            If cbStrong.Checked = True Then
                                pDestColor = Color.FromArgb(0,pSourceColor.B)
                            Else
                                pDestColor = pSourceColor
                            End If
                        Else
                            pDestColor = getAverage(pSourceColor)
                        End If
                    Case "P"
                        If cbP.Checked = True Then
                            If cbStrong.Checked = True Then
                                pDestColor = Color.FromArgb(pSourceColor.R,pSourceColor.B)
                            Else
                                pDestColor = pSourceColor
                            End If
                        Else
                            pDestColor = getAverage(pSourceColor)
                        End If
                    Case "Y"
                        If cbY.Checked = True Then
                            If cbStrong.Checked = True Then
                                pDestColor = Color.FromArgb(pSourceColor.R,0)
                            Else
                                pDestColor = pSourceColor
                            End If
                        Else
                            pDestColor = getAverage(pSourceColor)
                        End If
                    Case "C"
                        If cbC.Checked = True Then
                            If cbStrong.Checked = True Then
                                pDestColor = Color.FromArgb(0,pSourceColor.B)
                            Else
                                pDestColor = pSourceColor
                            End If
                        Else
                            pDestColor = getAverage(pSourceColor)
                        End If
                    Case Else
                        pDestColor = getAverage(pSourceColor)
                End Select
                destImg.SetPixel(i,j,pDestColor)
            Next
        Next
        picDest.Image = destImg
    End Sub
最后再来一张别的图片效果

好吧,还算不错。

由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供参考。

学习更多vb.net知识,请参看 vb.net 教程 目录

猜你在找的VB相关文章