WpfDemo.RgbaBitmapSource.CopyPixels C# (CSharp) Method

CopyPixels() public method

public CopyPixels ( System.Windows.Int32Rect sourceRect, Array pixels, int stride, int offset ) : void
sourceRect System.Windows.Int32Rect
pixels System.Array
stride int
offset int
return void
        public override void CopyPixels(Int32Rect sourceRect, Array pixels, int stride, int offset)
        {
            for (int y = sourceRect.Y; y < sourceRect.Y + sourceRect.Height; y++)
            {
                for (int x = sourceRect.X; x < sourceRect.X + sourceRect.Width; x++)
                {
                    int i = stride * y + 4 * x;
                    byte a = this.rgbaBuffer[i + 3];
                    byte r = (byte)((int)(this.rgbaBuffer[i] * a) / 256);
                    byte g = (byte)((int)(this.rgbaBuffer[i + 1] * a) / 256);
                    byte b = (byte)((int)(this.rgbaBuffer[i + 2] * a) / 256);
                    pixels.SetValue(b, i + offset);
                    pixels.SetValue(g, i + offset + 1);
                    pixels.SetValue(r, i + offset + 2);
                    pixels.SetValue(a, i + offset + 3);
                }
            }
        }