Skip to content

Instantly share code, notes, and snippets.

@yuvarajoo
Last active April 2, 2018 04:01
Show Gist options
  • Save yuvarajoo/05475d6e6117ec5d0cce0e9ca014f0c8 to your computer and use it in GitHub Desktop.
Save yuvarajoo/05475d6e6117ec5d0cce0e9ca014f0c8 to your computer and use it in GitHub Desktop.
Convert BitmapSource to Bitmap
private Bitmap GetBitmap(BitmapSource source)
{
Bitmap bmp = new Bitmap
(
source.PixelWidth,
source.PixelHeight,
System.Drawing.Imaging.PixelFormat.Format32bppPArgb
);
BitmapData data = bmp.LockBits
(
new System.Drawing.Rectangle(System.Drawing.Point.Empty, bmp.Size),
ImageLockMode.WriteOnly,
System.Drawing.Imaging.PixelFormat.Format32bppPArgb
);
source.CopyPixels
(
Int32Rect.Empty,
data.Scan0,
data.Height * data.Stride,
data.Stride
);
bmp.UnlockBits(data);
return bmp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment