本帖最后由 lwj167 于 2009-09-26 20:16:52 编辑

解决方案 »

  1.   

    System.Runtime.InteropServices.Marshal.Copy(pixelValues, 0, iptr, scanBytes); 
    iptr是你被转图片的指针,所以出错了,新建一个bitmap,传到里面就可以了
    Bitmap bit2 = new Bitmap(nWidth, nHeight);
                    BitmapData bitdate2 = bit2.LockBits(new Rectangle(0, 0, nWidth, nHeight), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                    Marshal.Copy(pixelValues, 0, bitdate2.Scan0, scanBytes);
    bmp.UnlockBits(bmpData);  // 解锁内存区域 
      

  2.   


    这样改了Marshal.Copy(pixelValues, 0, bitdate2.Scan0, scanBytes); 还是出现了同样的问题
      

  3.   


    我是想返回Bitmap,具体怎么说呢?
      

  4.   

    我给你看一下我的代码吧,是正常的,你看着改吧 
                try
                {
                    BitmapData bitdate = oldMap.LockBits(new Rectangle(0, 0, 1280, 720), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
                    int bSize = bitdate.Width;
                    int nMax = nOldWidth * nOldHeight;// 405504;
                    byte[] _old = new byte[nMax * 4];
                    Marshal.Copy(bitdate.Scan0, _old, 0, nMax * 4);                byte[] _DataBytes = new byte[nWidth * nHeight * 4];
                    int _nIndex = 0;
                    for (int i = 0; i < nOldHeight; i++)
                    {
                        if (i % 2 == 0)
                        {
                            Array.Copy(_old, i * nOldWidth * 4, _DataBytes, _nIndex * nOldWidth * 4, nOldWidth * 4);
                            _nIndex++;
                        }
                    }
                    Marshal.Copy(_DataBytes, 0, bitdate.Scan0, _DataBytes.Length);
                    oldMap.UnlockBits(bitdate);                Bitmap bit = new Bitmap(nWidth, nHeight);
                    BitmapData bitdate2 = bit.LockBits(new Rectangle(0, 0, nWidth, nHeight), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                    Marshal.Copy(_DataBytes, 0, bitdate2.Scan0, _DataBytes.Length);
                    bit.UnlockBits(bitdate2);
                    return bit;
                }
                catch { return null; }
      

  5.   

    找到问题所在了,你的BITDATE尺寸不符合要求,
    int scanBytes = stride * height;  // 用stride宽度,表示这是内存区域的大小 
    宽度就是图片的宽度,既然宽用的是线宽,就不用*3了,因为线宽就是每个行的所有像素总数,比如704长度的图片,线宽就是704*3
      

  6.   


    真的是呢,错是排出了可本应是彩色图像的变成了畸形的灰度图像。
    麻烦问一下,你有有根据R、G、B矩阵得到彩色图像的代码吗?
      

  7.   

    都说了要先进行RGB转换之后,再锁定赋值啊。另外,简单的乘以3也是不对的,要看具体格式和分辨率是72pdi还是96pdi的。
      

  8.   

    都说了要先进行RGB转换之后,再锁定赋值啊。另外,简单的乘以3也是不对的,要看具体格式和分辨率是72pdi还是96pdi的。
      

  9.   

    矩阵数据就是处理后得到的R、G、B矩阵,做他的传递参数,我这是要编一个用来调用的子函数的,想要弄个能普遍调用的,24位图彩色图像位图数据必须翻转是什么意思?能加一下我的QQ吗?1075932511
    谢谢哦~!呵呵
      

  10.   


    24位图的,我是把R\G\B附过去解锁的呀,你锁定是啥意思没懂,不过那样是可以的