C# 读取图像像素时出现异常
C# 读取图像像素时出现错误
最近在做C#上的图像处理,我的代码在读取图像像素时,针对有些二值图像不会报错,但有些二值图像却会报错,能有高手可以给我讲讲是怎么回事吗?
其中System.Drawing.Imaging.BitmapData aData = a.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, a.PixelFormat);报错
------解决方案--------------------
abytes = aData.str...*aData.Height;
试试
最近在做C#上的图像处理,我的代码在读取图像像素时,针对有些二值图像不会报错,但有些二值图像却会报错,能有高手可以给我讲讲是怎么回事吗?
//读取水印图片的像素数组
Rectangle arect = new Rectangle(0, 0, a.Width, a.Height);
System.Drawing.Imaging.BitmapData aData = a.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, a.PixelFormat);
//Get the address of the first line.
IntPtr aptr = aData.Scan0;
// Declare an array to hold the bytes of the bitmap.
int abytes = a.Width * a.Height;//水印图像像素个数
byte[] ArgbValues = new byte[abytes];//水印图像像素数组
// Copy the RGB values into the array.
System.Runtime.InteropServices.Marshal.Copy(aptr, ArgbValues, 0, abytes);
其中System.Drawing.Imaging.BitmapData aData = a.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, a.PixelFormat);报错
c#
图像处理
------解决方案--------------------
abytes = aData.str...*aData.Height;
试试