WPF/WinForms/GDI interop: converting a WriteableBitmap to a System.Drawing.Image?

前端 未结 3 962
春和景丽
春和景丽 2021-01-23 01:05

How can I convert a WPF WriteableBitmap object to a System.Drawing.Image?

My WPF client app sends bitmap data to a web service, and the web service needs to construct a

3条回答
  •  囚心锁ツ
    2021-01-23 01:35

    this blog post shows how to encode your WriteableBitmap as a jpeg image. Perhaps that helps?

    If you really want to transfer the raw image data (pixels) you could:

    1. create a System.Drawing.Bitmap with the correct size
    2. iterate over your raw data, convert the raw data to a System.Drawing.Color (e.g. via Color.FromArgb() and set each pixel color in the newly created image via SetPixel()

    I'd definitely prefer the first solution (the one described in the blog post).

提交回复
热议问题