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

版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。
这一篇介绍的是仅有红色、绿色或者蓝色分量的特效:

仅红色时候:

RNew=R
GNew=0
BNew=0

仅绿色时候:

RNew=0

GNew=G

BNew=0

仅蓝色时候:

RNew=0
GNew=0
BNew=B

使用的时候代码如下:

    '仅红色
    Private Sub btnOnlyRed_Click(sender As Object, e As EventArgs) Handles btnOnlyRed.Click
        Dim pSourceColor As Color
        Dim pDestColor As Color
 
        Dim destImg As New Bitmap(sourceImg.Width, sourceImg.Height)
        Dim R, G, B As Integer
 
        For i As Integer = 0 To sourceImg.Width - 1
            For j As Integer = 0 To sourceImg.Height - 1
                pSourceColor = sourceImg.GetPixel(i, j)
                R = pSourceColor.R
                G = 0
                B = 0
                pDestColor = Color.FromArgb(R, G, B)
                destImg.SetPixel(i, j, pDestColor)
            Next
        Next
        picDest.Image = destImg
    End Sub
 
    '仅绿色
    Private Sub btnOnlyGreen_Click(sender As Object, e As EventArgs) Handles btnOnlyGreen.Click
        Dim pSourceColor As Color
        Dim pDestColor As Color
 
        Dim destImg As New Bitmap(sourceImg.Width, sourceImg.Height)
        Dim R, G, B As Integer
 
        For i As Integer = 0 To sourceImg.Width - 1
            For j As Integer = 0 To sourceImg.Height - 1
                pSourceColor = sourceImg.GetPixel(i, j)
                R = 0
                G = pSourceColor.G
                B = 0
                pDestColor = Color.FromArgb(R, G, B)
                destImg.SetPixel(i, j, pDestColor)
            Next
        Next
        picDest.Image = destImg
    End Sub
 
    '仅蓝色
    Private Sub btnOnlyBlue_Click(sender As Object, e As EventArgs) Handles btnOnlyBlue.Click
        Dim pSourceColor As Color
        Dim pDestColor As Color
 
        Dim destImg As New Bitmap(sourceImg.Width, sourceImg.Height)
        Dim R, G, B As Integer
 
        For i As Integer = 0 To sourceImg.Width - 1
            For j As Integer = 0 To sourceImg.Height - 1
                pSourceColor = sourceImg.GetPixel(i, j)
                R = 0
                G = 0
                B = pSourceColor.B
                pDestColor = Color.FromArgb(R, G, B)
                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版权协议,转载请附上原文出处链接及本声明。

上一篇:Confluence 6 后台中的选择站点首页


下一篇:Confluence 6 自定义默认空间内容