I have two piece of unsafe code. In the first one I'm getting the byte*
pointer of a Bitmap data, and the second one in inside a loop that uses that
byte* pointer to set the data in the Bitmap.
The trouble is that that each of this pieces of code are bound by a
different unsafe section, therefore I'm getting an error that the second
unsafe section does not "The name 'refBuf' does not exist in the current
context"
////////////////////////////////////////////////////////////////
Bitmap img = new Bitmap(100, 200,
System.Drawing.Imaging.PixelFormat.Format32bppRgb) ;
int maxLines = 1234;
System.Drawing.Imaging.BitmapData refData = img.LockBits(
new Rectangle(0, 0, img.Width,
img.Height),
System.Drawing.Imaging.ImageLockMode.WriteOnly, img.PixelFormat);
unsafe
{
byte* refBuf = (byte*)refData.Scan0.ToPointer();
}
for( int line= 0; line< maxLines ; ++line)
{
Array buff = GetBuffer(line);
unsafe
{
// Copyieng the buff content to the refBuf...
// In here the refBuf is unknown !!!!
}
}
img.UnlockBits(refData);
////////////////////////////////////////////////////////////////
I need to set the byte* refBuf only once outside of the loop, but I also
need to use the byte* refBuf inside the loop.
What should I do to make this error go away?
--
Thanks
Sharon