Solved

BitBlt in VB

Posted on 2002-04-30
4
306 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now