请问关于 StretchBlt 函数

dell9 2003-08-19 02:16:33
当我用StretchBlt 把一个bmp中的内容拉伸到另一个bmp里时, 目标图片c.bmp成了全黑色,请问这是怎么回事?
我的源代码是 (VB)


Dim PIC1 As New StdPicture
Dim PIC2 As New StdPicture
Dim HoldBmp1&
Dim HoldBmp2&
Dim hdc1&, hdcRef1&
Dim hdc2&, hdcRef2&
Private hDesk1&
Private hDesk2&
Dim FName As String


Private Sub Command1_Click()
Dim i As Integer
Set PIC1 = LoadPicture(App.Path & "\B0D51.bmp")
Set PIC2 = LoadPicture(App.Path & "\B0D52.bmp")
HoldBmp1 = SelectObject(hdc1, PIC1.Handle)
HoldBmp2 = SelectObject(hdc2, PIC2.Handle)
'SetBkColor hdc2, RGB(0, 0, 0)
'SetBkMode hdc1, TRANSPARENT
'SetBkMode hdc2, TRANSPARENT
i = StretchBlt(hdc2, 0, 0, 11, 12, hdc1, 0, 0, 16, 16, SRCCOPY)
Debug.Print i

SavePicture PIC2, App.Path & "\c.bmp"
SelectObject hdc1, HoldBmp1
DeleteObject PIC1.Handle
SelectObject hdc2, HoldBmp2
DeleteObject PIC2.Handle

End Sub

Private Sub Form_Load()
hDesk1 = GetDesktopWindow()
hdcRef1 = GetDC(hDesk1)
hdc1 = CreateCompatibleDC(hdcRef1)
ReleaseDC hDesk1, hdcRef1
hDesk2 = GetDesktopWindow()
hdcRef2 = GetDC(hDesk2)
hdc2 = CreateCompatibleDC(hdcRef2)
ReleaseDC hDesk2, hdcRef2
End Sub
...全文
64 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
dell9 2003-08-20
  • 打赏
  • 举报
回复
还是黑的阿
yingyinghz 2003-08-20
  • 打赏
  • 举报
回复
VB 啊。。程序不是很懂 可能是源图像导入的问题吧。。不一定在StretchBlt函数上
shines77 2003-08-19
  • 打赏
  • 举报
回复
改为。。。。:

Dim PIC1 As New StdPicture
Dim PIC2 As New StdPicture
Dim HoldBmp1&
Dim HoldBmp2&
Dim hdc1&, hdcRef1&
Dim hdc2&, hdcRef2&
Private hDesk1&
Private hDesk2&
Dim FName As String


Private Sub Command1_Click()
Dim i As Integer
hDesk1 = GetDesktopWindow()
hdcRef1 = GetDC(hDesk1)
hdc1 = CreateCompatibleDC(hdcRef1)

hDesk2 = GetDesktopWindow()
hdcRef2 = GetDC(hDesk2)
hdc2 = CreateCompatibleDC(hdcRef2)

Set PIC1 = LoadPicture(App.Path & "\B0D51.bmp")
Set PIC2 = LoadPicture(App.Path & "\B0D52.bmp")
HoldBmp1 = SelectObject(hdc1, PIC1.Handle)
HoldBmp2 = SelectObject(hdc2, PIC2.Handle)
'SetBkColor hdc2, RGB(0, 0, 0)
'SetBkMode hdc1, TRANSPARENT
'SetBkMode hdc2, TRANSPARENT
i = StretchBlt(hdc2, 0, 0, 11, 12, hdc1, 0, 0, 16, 16, SRCCOPY)
Debug.Print i

SavePicture PIC2, App.Path & "\c.bmp"
SelectObject hdc1, HoldBmp1
DeleteObject PIC1.Handle
SelectObject hdc2, HoldBmp2
DeleteObject PIC2.Handle

DeleteDC hdc1
DeleteDC hdc2

ReleaseDC hDesk1, hdcRef1
ReleaseDC hDesk2, hdcRef2

End Sub

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧