SetPixel Issue

T

tamasumalta

I would like to change some pixels inside a particular gif file. I
tried using the setpixel and noticed that it is not compatible with
indexed images. Then I converted the file from a gif to a bmp using the
following syntax

imgDiskImage.Save(sNewFile, imgFormat)

Altough the file was converted it failed again when setpixel was called
in the statement

BMImage.SetPixel(Xindex, Yindex, Color.Cyan)

The error message in all the occasions is -
SetPixel is not supported for images with indexed pixel formats.

If I have converted the file to bitmap image why it is still failing?
What I should change? BMImage as declared as
Dim BMImage As Bitmap = CType(Image.FromFile(StrFileNamePath), Bitmap)

I have opened a bmp file created by windows paint and there were no
issues with the setpixel. So I've tried converting the gif file with
Microsoft Office Picture Manager to a bmp but this also failed.

Strange

Thanks
Jansen
 
H

Herfried K. Wagner [MVP]

I would like to change some pixels inside a particular gif file. I
tried using the setpixel and noticed that it is not compatible with
indexed images. Then I converted the file from a gif to a bmp using the
following syntax

imgDiskImage.Save(sNewFile, imgFormat)

Altough the file was converted it failed again when setpixel was called
in the statement

BMImage.SetPixel(Xindex, Yindex, Color.Cyan)

The error message in all the occasions is -
SetPixel is not supported for images with indexed pixel formats.

If I have converted the file to bitmap image why it is still failing?

The 'Bitmap' class can store both indexed and non-indexed images. GIF files
use a color table and are thus indexed. However, just create a new image of
the same size, use 'Graphics.FromImage(<new bitmap>)' to get a 'Graphics'
object and pass the image object containing the GIF file to its 'DrawImage'
method.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top