473,811 Members | 2,851 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.BitmapD ata refData = myBitmap.LockBi ts(new
Rectangle(0, 0, bmp.Width, bmp.Height),
System.Drawing. Imaging.ImageLo ckMode.WriteOnl y, bmp.PixelFormat );
byte* buff = refData.Scan0.T oPointer();

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.AccessV iolationExcepti on' 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 2421
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.co m

"Sharon" <Sh*****@newsgr oups.nospamwrot e in message
news:05******** *************** ***********@mic rosoft.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.BitmapD ata refData = myBitmap.LockBi ts(new
Rectangle(0, 0, bmp.Width, bmp.Height),
System.Drawing. Imaging.ImageLo ckMode.WriteOnl y, bmp.PixelFormat );
byte* buff = refData.Scan0.T oPointer();

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.AccessV iolationExcepti on' 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
23892
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 bitmap object. How to do this with C#? Any hints? Thank you very much. Best regards. Xiaoguang
4
2417
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) demands that I draw into the display by first creating a Bitmap, and then drawing into a DisplayContext using BitBlt(). The pseudocode looks something like: // Create an empty bitmap: HDC hScreen = GetDC (0); pHandle = CreateCompatibleBitmap...
9
1876
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 bitmap saved in memory. What I am trying to accomplish is generating a checksum value and returning that value from the bitmap stored in memory, but I cannot solve this problem. The method is designed to given a window handle, height, and...
12
3364
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 draw it into a Bitmap. Is there a graphics method that can help?
6
2478
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 that point to the colors in a Palette of the display driver. So if I get a bitmap via CF_BITMAP I need to also get a Palette off the clipboard and realize it then display the bitmap. I believe "Realize it" means to put it into the display driver.
3
2337
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 file so I can open it again by use filestream.but it is stupid. Can anyone tell me create bitmap instance by using palette data and pixel data? any reply is very thanksful.
20
7020
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 lData.GetDataPresent(DataFormats.Bitmap) Then Dim lPictureBox As New PictureBox
3
3725
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 pixel at row 3 col 5 = colour number is a and save it to disk as a 256 colour bitmap without any compresion as c:\a.bmp. no interface. i have microsoft visual c# 2008 express edition. help? thank you.
1
1485
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 'bmpOut.Palette = imageFile.Palette' line (see below). Anyone come across this or suggest a reason for the error? private static System.Drawing.Image CreateImageFile(System.Drawing.Image imageFile, int width, int height)
0
9722
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10379
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10393
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9200
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6882
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4334
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.