我将一个bitmap的rgb信息用LockBits方法放到了内存里面,每一个像素的rgb信息一共4个字节,第四个字节没有用。
现在我想将数组中存放的rgb信息转换成  RGB565 格式的,也就是说:R值:取高5位
G值:先取高6位的前3位组成一个字节G值:再取高6位的低3位
B值:取高5位这样就从原来的24位压缩到了16位各位达人,有没有什么好的建议

解决方案 »

  1.   

    位移运算 >> & <<...很简单自己写吧,去看看MSDN...
      

  2.   

    Bitmap.GetPixel(),比较慢
    BitmapData.Stride 
    BitmapData.Scan0 
    保存到数组循环移位
      

  3.   

    private void converToRGB565(int Ptr)
            {
                for (int i = 0; i < bytes; i = i + 4)
                {
                    byte transfer1 = (byte)(Marshal.ReadByte((IntPtr)(Ptr + 2)) & 0xF8 | Marshal.ReadByte((IntPtr)(Ptr + 1)) & 0x07);            }
            }
    先自己写了一点儿,把这个方法放在一个timer里面,但是这明显不行,效率低,整个程序就卡住不动
      

  4.   

    System.Drawing.Imaging.BitmapData imageData = image.LockBits(rect,System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppRgb);        //Get the address of the first line
            IntPtr ptr = imageData.Scan0;        private void converToRGB565(int Ptr)
            {
                for (int i = 0; i < bytes; i = i + 4)
                {
                    //FF + R + G + B 
                    uint rgbData = (uint)Marshal.ReadInt64((IntPtr)(Ptr + i));                byte transfer1 = (byte)((rgbData >> 16 & 0xF8) | (rgbData >> 13 & 0x07));
                    byte transfer2 = (byte)((rgbData >> 5 & 0xE0) | (rgbData >> 3 & 0x1F0));
                }
            }
    这怎么出错了,每次读到bytes大小是37200,每次读到37196的时候就报错