473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Error when Iterating through a bitmap data with palette

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.
--
Thanks
Sharon
Mar 29 '07 #1
2 2407
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?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Sharon" <Sh*****@newsgroups.nospamwrote in message
news:05**********************************@microsof t.com...
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.
--
Thanks
Sharon

Mar 29 '07 #2
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.
--
Thanks
Sharon
Apr 1 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ma Xiaoguang | last post by:
Dear ladies and gentlemen: How to access all the pixels of a bitmap with C#? I am working with Delphi before. In Delphi, you can use TBitmap.Scanline property to access all the pixels of a...
4
by: noleander | last post by:
Hey. I've got a color photo in a simple unsigned charRGB array. The photo does not exist on disk. I want to display the photo in my window. The application I am working in (not my choice)...
9
by: Kodiak | last post by:
I am passing in a reference to a window handle, followed by the height and width as well into my method. I am then creating a Device Context using the window handle and converting the window in a...
12
by: active | last post by:
I've been looking on the Internet for a way to convert a DIB to a Bitmap without success. Now I'm wondering if that is the approach I should be taking. All I want to do is display the DIB or...
6
by: \Frank\ | last post by:
I trying to learn what a Bitmap is. Not a Managed Bitmap Object but one that, for example, comes from the clipboard with CF_BITMAP. I'm guessing that a CompatableBitmap is an array of indices...
3
by: yang from china | last post by:
I cannot open TGA file use framework's class,so I am trying to convert TGA file to BMP file(or others).Now I have read the palette data and pixel data successfully.One way I create a temporary BMP...
20
by: Joe Duchtel | last post by:
Hello - I have the following code to get a bitmap from the clipboard and to save it to a *.png file ... Dim lData As IDataObject = Clipboard.GetDataObject() If...
3
by: radu | last post by:
i need a bit of help with few lines of code. 1. i have integer array a = numbers from 0 to 256 2. i have to create a 256 colours bitmap of 500x500 pixels, asign colours as matrix a. ex. bitmap at...
1
by: jj | last post by:
The following creates a copy of an image. It worked fine in Visual Studio 2005, but after installing Visual Studio 2008 then opening the solution as a ..net 2.0 project, I get an error on the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.