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

前端之家收集整理的这篇文章主要介绍了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,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,j)
                R = 0
                G = pSourceColor.G
                B = 0
                pDestColor = Color.FromArgb(R,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,j)
                R = 0
                G = 0
                B = pSourceColor.B
                pDestColor = Color.FromArgb(R,pDestColor)
            Next
        Next
        picDest.Image = destImg
    End Sub

运行时的效果如下:

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

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

原文链接:/vb/256708.html

猜你在找的VB相关文章