Using SetPixel with PixelFormat::Format8bppIndexed

meretrix

Member
Joined
Aug 14, 2003
Messages
13
After figuring out how to manipulate the palette on a Bitmap object, I now cant manage to make SetPixel work without throwing an exception. Ive tried:

SetPixel(x, y, FromArgb(0xAARRGGBB))
SetPixel(x, y, PredefinedColour)
SetPixel(x, y, Palette->Entries[0])
SetPixel(x, y, 0)

Help please...
 
System.ArgumentException. This is what happens when I try to use a predefined color or FromArgb. When I try to do it with a simple integer it just wont compile.
 
Are you making sure that x and y are Integers and not Doubles or Longs or anything? If Option Strict is on, it wont allow narrowing conversions.
 
Theyre definitely ints (set up as such in the for loops before). It seems like the functions not set up to handle a colour index, cos no matter what I do it either crashes or wont compile...
 
I think the problem is the pixel format (Format8bppIndexed). Some things VB cant do with an image in an indexed format. Can you convert the image to a non-indexed format? That was ultimately the solution to a similar problem I was having.
 
You could LockBits on the bitmap, then either use unsafe and access the pixels directly (fast). Or, use Marshal.Copy to copy from the Scan0 IntPtr to an array, alter various pixels in said array and Marshal.Copy it back (relatively slow). Then UnlockBits.
 
Back
Top