This method retrieves the RGB values and palette number of the specified pixel in the Device Independent Bitmap (DIB).
Public Function GetBitmapPixel(imgNo As Integer, x As Integer, y As Integer, palette As Byte, red As Byte, green As Byte, blue As Byte) As Boolean
public bool GetBitmapPixel(int imgNo, int x, int y, ref byte palette, ref byte red, ref byte green, ref byte blue);
Parameters
imgNo
The image number (from -1 to 99)
x,y
The x,y coordinates of the specified
pixel
palette
The palette number of the specified
pixel
red
The red component of the RGB value of
the specified pixel
green
The green component of the RGB value
of the specified pixel
blue
The blue component of the RGB value
of the specified pixel
Return Value
Returns True if successful. Returns False if unsuccessful.
Explanation
The GetBitmapPixel method retrieves the RGB values and palette number of the specified pixel in the Device Independent Bitmap (DIB). For 1, 4, and 8 bit images, the applicable values are set in the Palette parameter. For 16, 24, and 32 bit images, the applicable values are set in the red, green, and blue parameters.
The image used is the image set in the StartBitmapAccess method.
To access the bitmap and manipulate pixel data, you must use the
following methods as a group:
StartBitmapAccess
|
GetBitmapPixel, SetBitmapPixel
|
EndBitmapAccess
Example
The following code starts access to the DIB, then loops through each pixel in the image, using the GetBitmapPixel method to retrieve the pixels' rgb values. Then those values are reversed and set using the SetBitmapPixel method (For 1, 16, 24, or 32 bit images).
[Visual Basic] Dim IkEffect As Newtone.ImageKit.WPF.Effect Dim Ret As Boolean Dim i As Long, j As Long Dim PalNo As Integer, Red As Integer, Green As Integer, Blue As Integer IkEffect = New Newtone.ImageKit.WPF.Effect If IkEffect.SourceImage = Nothing Then Exit Sub Ret = IkEffect.StartBitmapAccess(0) If Ret = False Then Exit Sub
For i = 0 To IkEffect.SourceImage.Height - 1 For j = 0 To IkEffect.SourceImage.Width - 1 Ret = IkEffect.GetBitmapPixel(0, j, i, PalNo, Red, Green, Blue) If Image.GetPixelFormatSize(IkEffect.SourceImage.PixelFormat) = 1 Then If PalNo <> 0 Then PalNo = 0 Else PalNo = 1 End If Else If Image.GetPixelFormatSize(IkEffect.SourceImage.PixelFormat) > 8 Then Blue = 255 - Blue Green = 255 - Green Red = 255 - Red End If Ret = IkEffect.SetBitmapPixel(0, j, i, PalNo, Red, Green, Blue) Next j Next i Ret = IkEffect.EndBitmapAccess(0)