画像処理用の LockBitmap クラスを学習しようとしていますが、以下に投稿されたこのコードに出くわしました。基本的に、xy 座標の色を返します。
もちろん、この方法はsource.LockBits()and Marshal.Copy()/を実行した後にのみ機能しunsafe contextます。
public Color GetPixel(int x, int y, Bitmap source)
{
int Depth = System.Drawing.Bitmap.GetPixelFormatSize(source.PixelFormat);
int Width = source.Width;
int Height = source.Height;
Color clr = Color.Empty;
// Get color components count
int cCount = Depth / 8;
int PixelCounts = Width * Height;
byte[] Pixels = new byte[cCount * PixelCounts];
// Get start index of the specified pixel
int i = ((y * Width) + x) * cCount;
byte b = Pixels[i];
byte g = Pixels[i + 1];
byte r = Pixels[i + 2];
byte a = Pixels[i + 3]; // a
clr = Color.FromArgb(a, r, g, b);
return clr;
}
- は何ですか
cCount、なぜいつもDepth / 8ですか? int i = ((y * Width) + x) * cCount、これは (x,y) 座標から に変換する固定式Pixels[i]ですか? なんで?