开发者

Bitmap.GetHbitmap() fails on XP

My NET 2.0 Winforms app works beautifully on Vista and Windows 7 but a call to Bitmap.GetHbitmap() returns null on Windows XP (even with SP3). The underlying Bitmap is a PNG 开发者_高级运维and is loaded from resources. It is loaded correctly so it is down to GetHbitmap(). I have tried calling both overloads with the same result.


Watch out for memory leaks while debugging and working with .GetHBitmap

When you're using this function you need to delete the object manually!!

MSDN example: http://msdn.microsoft.com/en-us/library/1dz311e4.aspx

<System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")> _
    Private Shared Function DeleteObject (ByVal hObject As IntPtr) As Boolean
    End Function



    Private Sub DemonstrateGetHbitmap()
        Dim bm As New Bitmap("Picture.jpg")
        Dim hBitmap As IntPtr
        hBitmap = bm.GetHbitmap()

        ' Do something with hBitmap.
        DeleteObject(hBitmap)
    End Sub

and similar question: Image loading memory leak with C#

Regards

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜