【发布时间】:2010-01-04 11:35:24
【问题描述】:
我正在使用Marshal.Copy() 将像素信息从Bitmap 复制到int[] 数组中,问题在于传入该数组的信息全部错误,例如:
[0] = -8682109;
[1] = -8682109;
[2] = -8616573;
[3] = -8616573;
[4] = -8550527;
and so on...
方法的代码是:
private unsafe int[] BmpToBytes_Unsafe(Bitmap bmp)
{
BitmapData bData = bmp.LockBits(new Rectangle(new Point(), bmp.Size),
ImageLockMode.ReadOnly,
PixelFormat.Format32bppRgb);
// number of bytes in the bitmap
byteCount = bData.Stride * (bmp.Height);
int[] bytes = new int[byteCount / 4];
Marshal.Copy(bData.Scan0, bytes, 0, byteCount/4);
// don't forget to unlock the bitmap!!
bmp.UnlockBits(bData);
return bytes;
当我使用byte[]数组时,存储的信息是正确的,所以我不知道这里发生了什么。
【问题讨论】:
标签: c# bitmap marshalling