GetPixel and SetPixel example
 Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
      Const wd = 200
      Const ht = 200
      Dim colr As Color
      Dim img As Image = Image.FromFile("c:\A\faalogo.jpg")
      Dim bm0 As Bitmap = New Bitmap(img, wd, ht)
      Dim bm1 As Bitmap = New Bitmap(wd, ht)
      Dim bm2 As Bitmap = New Bitmap(wd, ht)
      Dim bm3 As Bitmap = New Bitmap(wd, ht)
      Dim xx, yy As Integer
      Dim rr1, gg1, bb1, rr2, gg2, bb2 As Byte
      Try
         e.Graphics.DrawImage(bm0, 0, wd) ' original
         For yy = 1 To ht - 1
            For xx = 1 To wd - 1
               Application.DoEvents()
               colr = bm0.GetPixel(xx, yy)
               rr1 = Not colr.R
               bb1 = Not colr.B
               gg1 = Not colr.G
               rr2 = colr.R / 2
               gg2 = colr.G / 2
               bb2 = colr.B / 2
               bm1.SetPixel(xx, yy, Color.FromArgb(255, rr1, gg1, bb1))
               bm2.SetPixel(xx, yy, Color.FromArgb(255, rr2, gg2, bb2))
               bm3.SetPixel(xx, yy, Color.FromArgb(255, colr.B, colr.G, colr.R))
               e.Graphics.DrawImage(bm1, 0, 0)
               e.Graphics.DrawImage(bm2, ht, wd)
               e.Graphics.DrawImage(bm3, ht, 0)
            Next xx
         Next yy
      Catch ee As Exception
         MsgBox(ee.Message)
      End Try
   End Sub
 

This bit of code demonstrates how to read pixels from a bitmap, and write pixels back into the bitmap. I took an ordinary png file, and read the pixels, got the color (which is what GetPixel returns) and manipulated them in various ways and wrote them back into another bitmap, the reults of which are shown in the screen clipping.

It shows the use of creating an Image from a file on the disk, and feeding that image into a Bitmap constructor. Then I do a GetPixel on each pixel. GetPixel returns a Color which is a structure that encodes just about everything about color. Color.R, Color.G, and Color.B contains the red, green, and blue amounts, 0 to 255. After changing the colors I used the SetPixel.FromArgb to set each pixel in three other bitmaps. The original is on the lower left

Reading and writing pixels opens up a whole world of possibilities. For example, if you read through each pixel and compare the current pixel color with that of a neighboring pixel, and you find that the two pixel colors a very different, you can write a black pixel at the current location to create an outline of picture.

10/19/2015
TheLonelyProgrammer.Net
Alone in a sea of non-programmers