안전하지 않은 코드 블록을 사용하거나 Marshal class을 사용할 수 있습니다.
public static byte[] GetBytesWithMarshaling(Bitmap bitmap)
{
int height = bitmap.Height;
int width = bitmap.Width;
//PixelFormat.Format24bppRgb => B|G|R => 3 x 1 byte
//Lock the image
BitmapData bmpData = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
// 3 bytes per pixel
int numberOfBytes = width * height * 3;
byte[] imageBytes = new byte[numberOfBytes];
//Get the pointer to the first scan line
IntPtr sourcePtr = bmpData.Scan0;
Marshal.Copy(sourcePtr, imageBytes, 0, numberOfBytes);
//Unlock the image
bitmap.UnlockBits(bmpData);
return imageBytes;
}
그것은 그렇게 쉬운 일이 아니다 : 나는이 방법으로 해결할 것입니다. 원시 데이터에서 다른 형식을 대상 형식으로 변환해야하며 이는 쉬운 일이 아닙니다. 적어도 이것이 내가 얼마나 알고 있는지. 'byte [] data = System.IO.File.ReadAllBytes ('file.bmp')'를 사용하여 데이터를 얻을 수 있지만, 포맷에 관해서 이야기했습니다. – MahanGM
fopen() 함수는 FileStream 또는 File.ReadAllBytes() 또는 Image.FromFile()보다 빠르거나 다르지 않습니다. 안전하지 않은 포인터를 사용하는 데 중점을 둡니다. GetPixel()의 대안입니다. Bitmap.LockBits()를 사용하면 많은 Google 검색 결과가 있습니다. –