更新时间:2022-06-18 06:09:22
如果你的图像是Bitmap,你可以使用
If your image is Bitmap you can use
LockBits 然后 Scan0 方法:
public static Byte[] BmpToArray(Bitmap value) {
BitmapData data = value.LockBits(new Rectangle(0, 0, value.Width, value.Height), ImageLockMode.ReadOnly, value.PixelFormat);
try {
IntPtr ptr = data.Scan0;
int bytes = Math.Abs(data.Stride) * value.Height;
byte[] rgbValues = new byte[bytes];
Marshal.Copy(ptr, rgbValues, 0, bytes);
return rgbValues;
}
finally {
value.UnlockBits(data);
}
}