Writing pixels to indexed bmp file

nicovdb

New member
Joined
Feb 28, 2013
Messages
2
Programming Experience
Beginner
I created a bmp file containing 16 color indexes. Is there a function like SetPixel that i can use for indexed bmp files?

ie: myBmpFile.SetPixel(x,y, colors.item(1)) This gives me the error: Value of type 'System.Windows.Media.Color' cannot be converted to 'System.Drawing.Color'.
 
Hi,

Your SetPixel method is fine from a structure point of view but the fact that you are using "Colors.X" implies that you have added a reference to PresentationCore in your project and then imported "System.Windows.Media" into your Class.

When setting a pixel colour in the bitmap you have to use System.Drawing.Color.X. Therefore your code should look like:-

VB.NET:
myBmpFile.SetPixel(x,y, System.Drawing.Color.X)

Hope that helps.

Cheers,

Ian
 
Thanks for the reply.
You have to use the media colors to load in the bmp palette (BitmapPalette Class (System.Windows.Media.Imaging)). What i'm trying to do is create a 8bit bmp file with color indexes. So a pixel gets a nr referring to a color in the palette.
So if you have a 10x10 pixel bitmap. The pixel array is 10x10 bytes. lets say the first byte (0,0) has the value 15. This says that the colour of this pixel of the bitmap is the colour value specified in index 23 in the colour value (palette) array.
So if i change the color in the index every color with the value 15 wil change color.
 
Hi,

My apologies, I have never used the BitmapPallette class that you have referenced so I cannot help you any further in this post. The only point I would make is that the solution I provided did solve the particular error that you originally posted.

I am sure that someone else here will be able to help you find the right solution.

Cheers,

Ian
 
Back
Top