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

前端之家收集整理的这篇文章主要介绍了vb.net 教程 5-13 图像处理之像素处理 2前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
3、逆反(底片)
算法:
原图像:颜色值color=(R,G,B)
新图像:
RNew=255-R
GNew=255-G
BNew=255-B
color=(RNew,GNew,BNew)

    '逆反
    Private Sub btnInversion_Click(sender As Object,e As EventArgs) Handles btnInversion.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 = pSourceColor.G
                B = pSourceColor.B
                R = 255 - R
                G = 255 - G
                B = 255 - B
                pDestColor = Color.FromArgb(R,B)
                destImg.SetPixel(i,j,pDestColor)
            Next
        Next
        picDest.Image = destImg
    End Sub
处理结果如下:

4、曝光
算法:先定义一个阈值,通常取得是128
原图像:颜色值color=(R,G,B)
新图像:
如果R<阈值,那么RNew=255-R
如果G<阈值,那么GNew=255-G
如果B<阈值,那么BNew=255-B
color=(RNew,GNew,BNew)

    '曝光
    Private Sub btnExposure_Click(sender As Object,e As EventArgs) Handles btnExposure.Click
        Dim pSourceColor As Color
        Dim pDestColor As Color

        Dim destImg As New Bitmap(sourceImg.Width,j)
                R = pSourceColor.R
                G = pSourceColor.G
                B = pSourceColor.B
                If R < 128 Then R = 255 - R
                If G < 128 Then G = 255 - G
                If B < 128 Then B = 255 - B
                pDestColor = Color.FromArgb(R,pDestColor)
            Next
        Next
        picDest.Image = destImg
    End Sub
处理结果如下:

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

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

猜你在找的VB相关文章