こんにちは。
Windows10でWPFのアプリケーションを開発しています。
Visual Studio 2015 Communityを使っています。
###前提・実現したいこと
System.Drawing.BitmapをSystem.Windows.Controls.Imageに変換したいです。
###発生している問題・エラーメッセージ
hBitmap = original.GetHbitmap();//<=この行でメモリ不足のエラーが出ます。
1280*1024ピクセル程度で300KBです。
###該当のソースコード
C#
1 [System.Runtime.InteropServices.DllImport("gdi32.dll")] 2 public static extern bool DeleteObject(IntPtr hObject); 3 public static System.Windows.Controls.Image 4 SystemDrawingBitmap2SystemWindowsControlsImage(System.Drawing.Bitmap original) { 5 6 IntPtr hBitmap = new IntPtr(); 7 System.Windows.Controls.Image newimage = null; 8 try { 9 hBitmap = original.GetHbitmap();//<=この行でメモリ不足のエラーが出ます。 10 newimage = new System.Windows.Controls.Image(); 11 newimage.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( 12 hBitmap, 13 IntPtr.Zero, 14 Int32Rect.Empty, 15 System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()); 16 } 17 finally { 18 DeleteObject(hBitmap); 19 } 20 return newimage; 21 }
###補足情報(言語/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
です。
よろしくお願いします。

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。