Link to home
Start Free TrialLog in
Avatar of toff_in_sydney
toff_in_sydney

asked on

BitBlt in VB

I have the following bit of code in my application:
    Set picSource.Picture = LoadPicture(sFile)
    Const PIXEL = 3
    picSource.ScaleMode = PIXEL
    picDest.ScaleMode = PIXEL
    hDestDC = picDest.hDC
    x = 0
    y = 0
    ' Assign information of the source bitmap.
    hSrcDC = picSource.hDC
    lReturn = BitBlt(hDestDC, _
                     0, _
                     0, _
                     iWidth, _
                     iHeight, _
                     hSrcDC, _
                     iLeft, _
                     iTop, _
                     &HCC0020)


The picture loads into picSource okay, and the DCs appear to be set up correctly. But after the BitBlt, picDest.picture is always empty (ie., 0). The idea of the exercise is to copy a section (bounded by iLeft, iTop, iWidth, iHeight) of the picture in picSource to picDest. But, obviously, it's not working. Why not?
Avatar of n_narayanan
n_narayanan
Flag of India image

Look at this Excellent Code

http://www.freevbcode.com/ShowCode.Asp?ID=3677

Narayanan
Drawing on the picturebox (or form) doesn't change its Picture property.
What will be different is picDest.Image, not picDest.Picture.
Use  "picDest.Picture = picDest.Image", or, after drawing, use "picDest.AutoRedraw = False", e.g.:

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    AutoRedraw = True
   
    ' draw something
    Me.Line -(X, Y)
   
    AutoRedraw = False   ' make permanent picture
End Sub
ASKER CERTIFIED SOLUTION
Avatar of ameba
ameba
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Explanation to EE (No, I am not asking you to change the grade)

I correctly answered the question, not with one solution, but with all practical solutions, and all with the required code.
solution 1:
Use  "picDest.Picture = picDest.Image"

solution 2:
is a complete drawing program which shows how to make permanent picture using AutoRedraw

I have also given the alternative to BitBlt:

>Instead of BitBlt, you can directly produce the picture using PaintPicture method.

It seems user have jumped to the alternative, without reading or understanding the first part of my post, and instead of posting feedback in this question, he posts a new question about PaintPicture.
https://www.experts-exchange.com/questions/20295350/PaintPicture.html