VB,bitblt函数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VB,bitblt函数相关的知识,希望对你有一定的参考价值。

我想让picture1的图片复制到picture2里,并且picture2里有一张图片,但是我复制过去后,picture2里的图片会像是主动给picture1的图片让出了位置一样。怎么样才能让picture1的图片在不影响picture2的情况复制在picture2上?

参考技术A BitBlt Picture2.hDC, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture1.hDC, 0, 0, vbSrcCopy追问

我就是这样弄的,但是不成,我把宽度和高度改成280之后,才得到了想要的,相当于图片叠加的样子。Picture1.ScaleWidth, Picture1.ScaleHeight这样设置出来,他截图却是picture2的高度和宽度,我也看过picture1和picture2是否弄反了,但是不是。十分十分郁闷···

追答

不是主动给picture1的图片让出了位置,而是把picture1+picture2一同复制贴进picture2了,因为单位不对,呵呵,这样试试:
BitBlt Picture2.hDC, 0, 0, Picture1.ScaleWidth / Screen.TwipsPerPixelX, Picture1.ScaleHeight / Screen.TwipsPerPixelY, Picture1.hDC, 0, 0, vbSrcCopy

本回答被提问者采纳

bitblt 函数问题

Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Sub Pic2_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Pic2.Paint
Pic2.BackColor = Color.Black
e.Graphics.DrawLine(Pens.Red, 0, 0, 100, 100)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
BitBlt(Pic1.CreateGraphics.GetHdc, 0, 0, 100, 100, Pic2.CreateGraphics.GetHdc, 0, 0, &HCC0020)
End Sub

请大家帮我看下这段代码,我想利用 bitblt 函数将 pic2 中的图像放到 pic1 中,但运行后,没有反应
此问题根据 CSDN 的网友 bw555 提供的代码已解决。

原因是对 bitblt 函数的声明不正确,修改如下:

Public Class Form1

Private Declare Function BitBlt Lib "GDI32" (ByVal srchDC As Integer, ByVal srcX As Integer, ByVal srcY As Integer, _
ByVal srcW As Integer, ByVal srcH As Integer, ByVal desthDC As Integer, _
ByVal destX As Integer, ByVal destY As Integer, ByVal op As Integer) As Integer

Const SRCCOPY As Integer = &HCC0020

Private Sub Pic2_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Pic2.Paint
Pic2.BackColor = Color.Black
e.Graphics.DrawLine(Pens.Red, 0, 0, 100, 100)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
BitBlt(Pic1.CreateGraphics.GetHdc, 0, 0, 100, 100, Pic2.CreateGraphics.GetHdc, 0, 0, SRCCOPY)
End Sub

End Class

参考技术A 属性栏autoredraw勾上, 然后把BitBlt写到FormActivate中, 并且加上循环试试~

以上是关于VB,bitblt函数的主要内容,如果未能解决你的问题,请参考以下文章

bitblt 函数问题

关于BitBlt函数

bitblt函数怎么用啊?

请教一下mfc中bitblt各个参数的具体含义

CDC的BitBlt函数

BitBlt 函数 详解2 附Demo