VB和API绘图的速度比较

Option Explicit Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long Private Declare Function GetTickCount Lib "kernel32" () As Long Private Sub Command1_Click() Dim c As Long Me.Caption = "正在翻转..." c = GetTickCount() If PictureInvHAPI(Picture1) = 1 Then Me.Caption = "翻转完成,用时 " & CStr(GetTickCount() - c) & " 毫秒!" End If End Sub Public Function PictureInvHAPI(pic As PictureBox) As Long Dim w As Integer, h As Integer Dim sm As Long, ar As Boolean Dim i As Long, j As Long Dim clr As Long sm = pic.ScaleMode ar = pic.AutoRedraw pic.ScaleMode = 3 pic.AutoRedraw = True w = pic.ScaleWidth - 1 h = pic.ScaleHeight - 1 For j = 0 To h For i = 0 To (w - (w Mod 2)) / 2 clr = GetPixel(pic.hdc, i, j) 'Debug.Print clr SetPixel pic.hdc, i, j, GetPixel(pic.hdc, w - i, j) SetPixel pic.hdc, w - i, j, clr Next i Next j pic.Refresh pic.ScaleMode = sm pic.AutoRedraw = ar PictureInvHAPI = &H1 End Function Public Function PictureInvH(pic As PictureBox) As Long Dim w As Integer, h As Integer Dim sm As Long, ar As Boolean Dim i As Long, j As Long Dim clr As Long sm = pic.ScaleMode ar = pic.AutoRedraw pic.ScaleMode = 3 pic.AutoRedraw = True w = pic.ScaleWidth - 1 h = pic.ScaleHeight - 1 For j = 0 To h For i = 0 To (w - (w Mod 2)) / 2 clr = pic.Point(i, j) 'Debug.Print clr pic.PSet (i, j), pic.Point(w - i, j) pic.PSet (w - i, j), clr Next i Next j pic.ScaleMode = sm pic.AutoRedraw = ar PictureInvH = &H1 End Function

从上面的代码来测试,225X121的图片 3GHz AMD 双核CPU 4G内存,VB代码平均使用450ms 而 API使用350ms

加上hdc = GetDC(pic.hWnd) 和 ReleaseDC 两者竟然出奇的一致

也再一次说明VB不过用类封装了大量的WindowsAPI

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值