Error when Iterating through a bitmap data with palette

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm using a Bitmap that has a palette of 256 colors (256 bytes).
I'm taking the Bitmap data by:

System.Drawing.Imaging.BitmapData refData = myBitmap.LockBits(new
Rectangle(0, 0, bmp.Width, bmp.Height),
System.Drawing.Imaging.ImageLockMode.WriteOnly, bmp.PixelFormat);
byte* buff = refData.Scan0.ToPointer();

And on this buff I'm iterating to set its data.

The problem is that at some point of the iteration I'm getting the following
error:

"An unhandled exception of type 'System.AccessViolationException' occurred
in 1000Gates.exe

Additional information: Attempted to read or write protected memory. This is
often an indication that other memory is corrupt."

I'm suspecting that I'm overwriting the palette data of the bitmap.

Does my suspicion is correct?

How should I correct this failure and successfully iterate through the whole
bitmap data.
 
Sharon,

It's possible, but without seeing how you are iterating over the data,
it's hard to say.

Doesn't the debugger show you which line it throws at?
 
Ok. I found that the Palette is included in the bitmap buffer I'm working on.
It was simply a miscalculation of the buffer index that cause index if the
buffer to get outside of the buffer bounds.
 

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

Back
Top