Yanshof
Yanshof

Reputation: 9926

How to convert ImageSource to bitmap?

I need to convert ImageSource to simple Bitmap ( System.Drawing.Bitmap )

How can i do it ?

Thanks

Upvotes: 1

Views: 6571

Answers (1)

Nasenbaer
Nasenbaer

Reputation: 4900

Public Function WpfBitmapSourceToBitmap(ByVal source As BitmapSource) As System.Drawing.Bitmap
    Dim bmp As New System.Drawing.Bitmap(source.PixelWidth, source.PixelHeight, System.Drawing.Imaging.PixelFormat.Format32bppPArgb)
    Dim data As System.Drawing.Imaging.BitmapData = bmp.LockBits(New System.Drawing.Rectangle(System.Drawing.Point.Empty, bmp.Size), System.Drawing.Imaging.ImageLockMode.[WriteOnly], System.Drawing.Imaging.PixelFormat.Format32bppPArgb)
    source.CopyPixels(Int32Rect.Empty, data.Scan0, data.Height * data.Stride, data.Stride)
    bmp.UnlockBits(data)
    Return bmp
End Function

Upvotes: 4

Related Questions