Solved

BitBlt in VB

Posted on 2002-04-30
4
311 Views
Last Modified: 2010-07-27
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?
0
Comment
Question by:toff_in_sydney
  • 3
4 Comments
 
LVL 3

Expert Comment

by:n_narayanan
ID: 6980028
Look at this Excellent Code

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

Narayanan
0
 
LVL 15

Expert Comment

by:ameba
ID: 6980044
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
0
 
LVL 15

Accepted Solution

by:
ameba earned 300 total points
ID: 6980058
picDest.Image will have the size of the control, so you'll have to set dimensions of picDest.

Instead of BitBlt, you can directly produce the picture using PaintPicture method.
0
 
LVL 15

Expert Comment

by:ameba
ID: 7137404
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.
http://www.experts-exchange.com/visualbasic/Q_20295350.html
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question