Last active
April 2, 2018 04:01
-
-
Save yuvarajoo/05475d6e6117ec5d0cce0e9ca014f0c8 to your computer and use it in GitHub Desktop.
Convert BitmapSource to Bitmap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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