こんにちは。
Windows10でWPFのアプリケーションを開発しています。
Visual Studio 2015 Communityを使っています。
###前提・実現したいこと
System.Drawing.BitmapをSystem.Windows.Interop.InteropBitmapに変更したいです。
または、System.Windows.Controls.ImageをSystem.Windows.Interop.InteropBitmapにしたいです。
###試したこと
下記のコード。
###発生している問題・エラーメッセージ
いずれも変換できないとのメッセージがでています。
###該当のソースコード
C#
1 public System.Windows.Interop.InteropBitmap 2 SystemDrawingBitmap2InteropBitmap(System.Drawing.Bitmap original) { 3 4 IntPtr hBitmap = original.GetHbitmap(); 5 System.Windows.Interop.Imaging newimage = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( 6 hBitmap, 7 IntPtr.Zero, 8 Int32Rect.Empty, 9 System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()); 10 DeleteObject(hBitmap); 11 return newimage; 12 }
C#
1 public System.Windows.Interop.InteropBitmap 2 SystemDrawingBitmap2InteropBitmap(System.Drawing.Bitmap original) { 3 4 IntPtr hBitmap = original.GetHbitmap(); 5 System.Windows.Controls.Image image = new System.Windows.Controls.Image(); 6 image.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( 7 hBitmap, 8 IntPtr.Zero, 9 Int32Rect.Empty, 10 System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()); 11 DeleteObject(hBitmap); 12 return image; 13 }
###補足情報(言語/FW/ツール等のバージョンなど)
Microsoft Visual Studio Community 2015
Version 14.0.25424.00 Update 3
Microsoft .NET Framework
Version 4.6.01038
インストールしているバージョン:Community
Visual C# 2015 00322-20000-00000-AA575
Microsoft Visual C# 2015
です。
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー