Good morning to everyone. Please help:
Bitmap b= new Bitmap("H:/project/program/bala.bmp");
int[] image=new int[b.Width*b.Height];
BitmapData lockData = b.LockBits(
new Rectangle(0, 0, b.Width, b.Height),
System.Drawing.Imaging.ImageLockMode.ReadWrite ,
System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
try
{
System.Runtime.InteropServices.Marshal.Copy(
lockData.Scan0, image, 0, image.Length);
Marshal.Copy(image, 0, lockData.Scan0, image.Length);
}
catch (Exception e)
{
Console.WriteLine(e);
}
b.UnlockBits(lockData);
This program produces the error
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at System.Runtime.InteropServices.Marshal.CopyToManaged(IntPtr source, Object destination, Int32 startIndex, Int32 length)
[From second Question]
Good morning to everyone.
I have tried the SetPixel function to set the pixel value in the image. But the SetPixel method shows an error for the indexed pixel format images. Please reply for this question.