首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C# 读取图像像素时出现异常

2013-03-25 
C# 读取图像像素时出现错误最近在做C#上的图像处理,我的代码在读取图像像素时,针对有些二值图像不会报错,

C# 读取图像像素时出现错误
最近在做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;
试试

热点排行