|  | 分類:[C#]
 
 
 VisualBasic2005 C#を使用しています。
LockBitsを使用して絵の色を操作しようとしているのですが、配列内のデータの並びが分からずに困っています。
            
      Rectangle rect2 = new Rectangle(0, 0, w, h);
            BitmapData bmpDate = mat.LockBits(rect, ImageLockMode.ReadWrite, mat.PixelFormat);
      IntPtr ptr = bmpDate.Scan0;
            int bytes = w * h * 3;
            byte[] rgbValues = new byte[bytes];
            System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);
このあたりで、rgbValuesにデータが入っているのは分かるのですが。
どのような情報がどういう並びで入っているのでしょうか?
分かったのは、絵の左上端1ピクセルのRGBの色情報がrgbValues[0]〜[2]にBGRという順番で入っているのはわかったのですが、他のビットの色をフォトショップで見たところ情報と合いませんでした。
rgbValues[0] ←B
rgbValues[1] ←G
rgbValues[2] ←R
rgbValues[3]
private void SetPixcel()
        {
            Rectangle rect2 = new Rectangle(0, 0, w, h);
            BitmapData bmpDate = mat.LockBits(rect, ImageLockMode.ReadWrite, mat.PixelFormat);
            IntPtr ptr = bmpDate.Scan0;
            int bytes = w * h * 3;
            byte[] rgbValues = new byte[bytes];
            System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);
            ///////rgbValuesの値を配列に入れる
            for (int ret = 0; ret < 3; ret++)
            {
                for (int z = ret; z < h * w * 3; z=z + 3) 
                {
                    int x2=0,y2=0;
                    y2 = z / 3;
                    if(y2<=h)
                    {
                    ar[x2, y2][ret] = rgbValues[z];
                    }
                    x2++;
                    if (x2 > w) {x2 =1; }
                    
                }
            }
    }
 |