| 
                  | Title | Use BitBlt, StretchBlt, and PaintPicture and compare their speeds | 
|---|
 | Keywords | BitBlt, StretchBlt, PaintPicture, performance, copy picture | 
|---|
 | Categories | Controls, Graphics | 
|---|
 | 
              
              
                | Private Sub cmdPaintPicture_Click()
Dim num_trials As Integer
Dim trial As Integer
Dim start_time As Single
Dim stop_time As Single
Dim wid As Single
Dim hgt As Single
    num_trials = CInt(txtTrials.Text)
    wid = picFrom.ScaleWidth
    hgt = picFrom.ScaleHeight
    lblTime.Caption = ""
    Screen.MousePointer = vbHourglass
    DoEvents
    start_time = Timer
    For trial = 1 To num_trials
        picTo.Cls
        picTo.Refresh
        picTo.PaintPicture picFrom.Picture, 0, 0
        picTo.Refresh
    Next trial
    DoEvents
    stop_time = Timer
    Screen.MousePointer = vbDefault
    lblTime.Caption = _
        Format$(stop_time - start_time, "0.0000") & _
        " sec"
End Sub
Private Sub cmdBitBlt_Click()
Dim num_trials As Integer
Dim trial As Integer
Dim start_time As Single
Dim stop_time As Single
Dim wid As Single
Dim hgt As Single
    num_trials = CInt(txtTrials.Text)
    wid = picFrom.ScaleWidth
    hgt = picFrom.ScaleHeight
    lblTime.Caption = ""
    Screen.MousePointer = vbHourglass
    DoEvents
    start_time = Timer
    For trial = 1 To num_trials
        picTo.Cls
        picTo.Refresh
        BitBlt picTo.hDC, 0, 0, wid, hgt, _
            picFrom.hDC, 0, 0, _
            SRCCOPY
        picTo.Refresh
    Next trial
    DoEvents
    stop_time = Timer
    Screen.MousePointer = vbDefault
    lblTime.Caption = _
        Format$(stop_time - start_time, "0.0000") & _
        " sec"
End Sub
Private Sub cmdStretchBlt_Click()
Dim num_trials As Integer
Dim trial As Integer
Dim start_time As Single
Dim stop_time As Single
Dim wid As Single
Dim hgt As Single
    num_trials = CInt(txtTrials.Text)
    wid = picFrom.ScaleWidth
    hgt = picFrom.ScaleHeight
    lblTime.Caption = ""
    Screen.MousePointer = vbHourglass
    DoEvents
    start_time = Timer
    For trial = 1 To num_trials
        picTo.Cls
        picTo.Refresh
        StretchBlt picTo.hDC, 0, 0, wid, hgt, _
            picFrom.hDC, 0, 0, wid, hgt, _
            SRCCOPY
        picTo.Refresh
    Next trial
    DoEvents
    stop_time = Timer
    Screen.MousePointer = vbDefault
    lblTime.Caption = _
        Format$(stop_time - start_time, "0.0000") & _
        " sec"
End Sub |