Solved

BitBlt in VB

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Macro which automatically send Excel spreadsheet to Outlook problem 2 61
VB6 Compile Compatibility Issue 4 90
TT Auto Dashboard 13 85
Advice in Xamarin 21 57
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 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

27 Experts available now in Live!

Get 1:1 Help Now