dcsimg
 

Image Negations

by Developer.com Staff

Image Negations

The Basic Principle of Making neagtive image from a normal one involves complimenting colors.The process of complementing involves representing colors in a three dimensional cube with the basic colors RGB as the three axis of the cube. When all colors are represented in a cube the opposite corners represent the Complement of the color.

Complement of white is black, complement of blue is yellow. Complementing can be done using the RGB combination.

white rgb(255,255,255)

The complement of white can be obtained by rgb(255-255,255-255,255-255) which has rgb(0,0,0) which is black.

The same concept as above is used in the program but just converted the integers to hexadecimal for the ease of calculation.

For i = 0 To Picturebox.ScaleHeight - 1
    For j = 0 To Picturebox.ScaleWidth - 1
      pixvalue = Picturebox.Point(j, i)
      hex_pixval = Hex(pixvalue)
      red_val = "&h" & Mid$(hex_pixval, 5, 2)
      green_val = "&h" & Mid$(hex_pixval, 3, 2)
      blue_val = "&h" & Mid$(hex_pixval, 1, 2)

      If red_val = "&h" Then red_val = "&h0"
      If green_val = "&h" Then green_val = "&h0"
      If blue_val = "&h" Then blue_val = "&h0"

      red_val = &HFF - red_val
      green_val = &HFF - green_val
      blue_val = &HFF - blue_val

      Picturebox.PSet (j, i), RGB(red_val, green_val, blue_val)
    Next
Next

This article was originally published on Wednesday Nov 20th 2002
Home
Mobile Site | Full Site