Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi,
 
I have control bitmap data using unsafe code,which is working perfectly in 2008 whereas the same code is raising memory access violation exception when run in vs 2010.
 
The code is as below:
Bitmap canvas = new Bitmap(pictureWater.Width, pictureWater.Height);
BitmapData data = canvas.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
 
byte* pixel = (byte*)data.Scan0.ToPointer();
pixel[0] = (byte)0;//blue
pixel[1] = (byte)color;//green
pixel[2] = (byte)0;//red
pixel[3] = (byte)255;
 
I have verified framework .Net 4.0 using verification tool and succeeded.
The system is running on 32 bit windows XP service pack3
 
Can anybody help,what might be the problem?
Posted 26-Jun-12 19:05pm
Edited 26-Jun-12 19:19pm
v2
Comments
Bernhard Hiller at 27-Jun-12 5:13am
   
Are pictureWater.Width and width the same? Also height.
Did you try ImageLockMode.ReadWrite?
MicroSoft's example at http://msdn.microsoft.com/en-us/library/5ey6h79d.aspx uses some Marshalling.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

yes, i have tried ImageLockMode.ReadWrite too, but still no use..
 
and width = canvas.Width;
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Instead of
byte* pixel = (byte*)data.Scan0.ToPointer();
 
use
byte* pixel = (byte*)data.Scan0;
 
Refer this link[^] for bitmap read write operaton.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 6,649
1 Sergey Alexandrovich Kryukov 6,270
2 CPallini 5,190
3 George Jonsson 3,574
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 3 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100