Invert an image - Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

This is a tutorial on how to invert an image in visual basic .net

invert image in visual basic .net

For this tutorial you need 2 Pictureboxes and a button

One picture box will display the original image and the other will show the inverted image

Load a picture into picturebox1:

convert an image to a negative format in visual basic

Convert Button Code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim pic As New Bitmap(PictureBox1.Image)
        For y As Integer = 0 To pic.Height - 1
            For x As Integer = 0 To pic.Width - 1
                Dim inv As Color = pic.GetPixel(x, y)
                inv = Color.FromArgb(255, 255 - inv.R, 255 - inv.G, 255 - inv.B)
                pic.SetPixel(x, y, inv)
                PictureBox2.Image = pic
            Next x
        Next y
    End Sub

Share This

Home | About | Contact | Privacy Policy

Copyright 2017 - All Rights Reserved.