bitblt 函数问题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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中, 并且加上循环试试~

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

关于BitBlt函数

bitblt函数怎么用啊?

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

CDC的BitBlt函数

BitBlt 函数 详解2 附Demo

如何加快 BitBlt 以使用 aero 捕获屏幕?