VB 多次调用StretchBlt 导致失败的问题
我在程序中调用StretchBlt函数对一个400*400的位图放大8倍后显示,可是该程序同时开启大约4个之后StretchBlt函数开始返回0值,图像不能被正确放大,是...
我在程序中调用StretchBlt函数对一个400*400的位图放大8倍后显示,可是该程序同时开启大约4个之后StretchBlt函数开始返回0值,图像不能被正确放大,是我的内存太小(512M)还是别的原因?
Private Sub load_map(num As Long)
Dim l as long
DeleteDC hMemDc
DeleteDC hMemDc1
Set PicBmp = LoadPicture(App.Path & "\map\" & CStr(num) & ".map")
Dim bm As BITMAP
Dim hBitmap1 As Long, holdmap As Long
GetObject PicBmp.Handle, Len(bm), bm
w = bm.bmWidth
h = bm.bmHeight
hMemDc = CreateCompatibleDC(hdc)
SelectObject hMemDc, PicBmp.Handle
w1 = w * 8
h1 = h * 8
hMemDc1 = CreateCompatibleDC(hdc)
hBitmap1 = CreateCompatibleBitmap(hdc, w1, h1)
holdmap = SelectObject(hMemDc1, hBitmap1)
l = StretchBlt(hMemDc1, 0, 0, w1, h1, hMemDc, 0, 0, w, h, vbSrcCopy)
DeleteObject hBitmap1
If holdmap <> 0 Then
DeleteObject holdmap
End If
If l = 0 Then Msgbox "显示地图:" & map_num & "失败"
End Sub 展开
Private Sub load_map(num As Long)
Dim l as long
DeleteDC hMemDc
DeleteDC hMemDc1
Set PicBmp = LoadPicture(App.Path & "\map\" & CStr(num) & ".map")
Dim bm As BITMAP
Dim hBitmap1 As Long, holdmap As Long
GetObject PicBmp.Handle, Len(bm), bm
w = bm.bmWidth
h = bm.bmHeight
hMemDc = CreateCompatibleDC(hdc)
SelectObject hMemDc, PicBmp.Handle
w1 = w * 8
h1 = h * 8
hMemDc1 = CreateCompatibleDC(hdc)
hBitmap1 = CreateCompatibleBitmap(hdc, w1, h1)
holdmap = SelectObject(hMemDc1, hBitmap1)
l = StretchBlt(hMemDc1, 0, 0, w1, h1, hMemDc, 0, 0, w, h, vbSrcCopy)
DeleteObject hBitmap1
If holdmap <> 0 Then
DeleteObject holdmap
End If
If l = 0 Then Msgbox "显示地图:" & map_num & "失败"
End Sub 展开
1个回答
展开全部
你的DC每次有没有销毁。
你可能重复了DC。
把代码贴上来看看。
Private Sub load_map(num As Long)
Dim l as long
Set PicBmp = LoadPicture(App.Path & "\map\" & CStr(num) & ".map")
Dim bm As BITMAP
Dim hBitmap1 As Long, holdmap As Long
GetObject PicBmp.Handle, Len(bm), bm
w = bm.bmWidth
h = bm.bmHeight
hMemDc = CreateCompatibleDC(hdc)
SelectObject hMemDc, PicBmp.Handle
w1 = w * 8
h1 = h * 8
hMemDc1 = CreateCompatibleDC(hdc)
hBitmap1 = CreateCompatibleBitmap(hdc, w1, h1)
holdmap = SelectObject(hMemDc1, hBitmap1)
l = StretchBlt(hMemDc1, 0, 0, w1, h1, hMemDc, 0, 0, w, h, vbSrcCopy)
DeleteObject hBitmap1
If holdmap <> 0 Then
DeleteObject holdmap
End If
DeleteDC hMemDc
DeleteDC hMemDc1
If l = 0 Then Msgbox "显示地图:" & map_num & "失败"
End Sub
你可能重复了DC。
把代码贴上来看看。
Private Sub load_map(num As Long)
Dim l as long
Set PicBmp = LoadPicture(App.Path & "\map\" & CStr(num) & ".map")
Dim bm As BITMAP
Dim hBitmap1 As Long, holdmap As Long
GetObject PicBmp.Handle, Len(bm), bm
w = bm.bmWidth
h = bm.bmHeight
hMemDc = CreateCompatibleDC(hdc)
SelectObject hMemDc, PicBmp.Handle
w1 = w * 8
h1 = h * 8
hMemDc1 = CreateCompatibleDC(hdc)
hBitmap1 = CreateCompatibleBitmap(hdc, w1, h1)
holdmap = SelectObject(hMemDc1, hBitmap1)
l = StretchBlt(hMemDc1, 0, 0, w1, h1, hMemDc, 0, 0, w, h, vbSrcCopy)
DeleteObject hBitmap1
If holdmap <> 0 Then
DeleteObject holdmap
End If
DeleteDC hMemDc
DeleteDC hMemDc1
If l = 0 Then Msgbox "显示地图:" & map_num & "失败"
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询