24 비트 Color 비트 맵 데이터를 Int32 배열에 복사하려고하는데 다음 코드를 작성했습니다.비트 맵 데이터를 Int32 배열로 복사 할 때 액세스 위반이 발생합니다.
Width of image = 200 pixels
Height of image = 150 pixels
public static Int32[] readBitmap()
{
int rows = 150;
int columns = 200;
Bitmap myBmp = new Bitmap("puppy.bmp");
BitmapData bmd = myBmp.LockBits(new Rectangle(0, 0, columns, rows), ImageLockMode.ReadWrite, myBmp.PixelFormat);
Console.WriteLine(myBmp.PixelFormat.ToString());
int fileSize = 30000; // 200 * 150
Int32[] fileBufferArray = new Int32[fileSize];
unsafe
{
for (int j = 0; j < rows; j++)
{
Int32* row = (Int32*)bmd.Scan0 + (j * bmd.Stride);
for (int i = 0; i < columns; i++)
{
try
{
fileBufferArray[j * columns + i] = row[i];
}
catch (Exception e)
{
Console.WriteLine(e.ToString() + " " + i.ToString() + " " + j.ToString());
break;
}
}
}
myBmp.UnlockBits(bmd);
return fileBufferArray;
} //unsafe
}
하지만 액세스 위반 예외가 발생합니다.
Unhandled Exception: System.AccessViolationException: Attempted to read or write
protected memory. This is often an indication that other memory is corrupt.
누군가이 오류를 해결할 수 있도록 도와 줄 수 있습니까?
안녕 난이 30000 길이 int 배열을 사용했다. 아니 3000 – user581734
@ user581734 : 고마워요. 네 말이 맞아, 30,000. 응답은 아직도 서있다. 비트 맵 데이터 배열의 값은 90,000 개이며 배열을 30,000 개의 값으로 복사하려고합니다. 실패 할 것입니다. –