gpt4 book ai didi

c# - Bitmap.GetHbitmap() 在 XP 上失败

转载 作者:行者123 更新时间:2023-11-30 13:05:12 29 4
gpt4 key购买 nike

我的 NET 2.0 Winforms 应用程序在 Vista 和 Windows 7 上运行良好,但调用 Bitmap.GetHbitmap() 在 Windows XP(即使是 SP3)上返回 null。底层的 Bitmap 是一个 PNG 并且是从资源中加载的。它被正确加载,所以它是 GetHbitmap()。我试过用相同的结果调用两个重载。

最佳答案

调试和使用 .GetHBitmap 时注意内存泄漏

使用此功能时需要手动删除对象!!

MSDN 示例: 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

和类似的问题: Image loading memory leak with C#

问候

关于c# - Bitmap.GetHbitmap() 在 XP 上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5818741/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com