版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。
之前两节都是保留的单一色系,这次我们要尝试保留多个色系。
还是先看看运行效果,保留绿、蓝、紫、黄这几个色系颜色:
有了上两节的基础,这次很容易理解。
'自定义
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, 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, 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, 0, 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, pSourceColor.G, 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.G, 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教程 目录
————————————————
版权声明:本文为CSDN博主「VB.Net」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。