PaintPicture problem

Posted on 1998-06-11
Last Modified: 2008-02-01
Hello all,

I am having a problem with the paintpicture method.  I load a picture file into a picturebox using the loadpicture method.
   set pic2.picture = loadpicture("c:\vermont.jpg")

Then I use the paintpicture method to paint the picture to another picturebox control.
   pic1.paintpicture pic2.picture, 0, 0, 1000, 1000

At this point the, although the picture paints on the screen, the picture property of pic1 is 0, the type property of pic1 is 0, indicating no picture.  So if I try to use another paintpicture, which is what I want to do to paint this to the printer object, I get an "invalid picture" error.
    printer.paintpicture pic1.picture 0, 0   ' results in error

Can anyone tell me why this is happening and what can be done about it?  I've tried using a .bmp file just to see if that was the problem, using the image property to work with the pictures (which does work and does print, but not what I want.  Either is doesn't size properly or prints in greyscale).

Thanks much
Question by:jamespaul
  • 3
  • 3
  • 2
  • +1

Expert Comment

ID: 1463101
Try using the RasterOp vbSrcCopy.

Btw, you do know that you can simply do this?
   Set Picture2.Picture = Picture1.Picture

Or, are your needs more complex?


Author Comment

ID: 1463102
Thanks for the comment.  I need to change the size of the image, then print it at that size.  You answered a question for me a couple of days ago about a richtextbox.  I'm trying to print id cards.   So not only do I need to move the picture from the TWAIN source, I need to size it and display it for the user to see, and print it and everything on the id card (which I'm hoping at this time can be a picturebox and the paintpicture method), including graphics and text.  This may not work well, as I'm not sure how the text will look and whether standard printer fonts will work better.  In that case I'll try the moveing the picture and text to the print object, but I don't know if it supports both text and graphics.  The printform method (if I change to a form) is done as a bitmap and the manual seems to recommend not using this.  I'll look up the function you mentioned and see if it fits my needs.  Thanks again.

Author Comment

ID: 1463103
Whoops, not a function.  I tried the vbSrcCopy with the paintpicture, but alas, to no avail.
Thanks for the suggestion.

Accepted Solution

clifABB earned 100 total points
ID: 1463104
Try using bitblt instead:
Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

Dim lRes As Long

To Paint Picture from pic1 to pic2
  lRes = BitBlt(pic2.hDC, 0, 0, 1000 / Screen.TwipsPerPixelX, 1000 / Screen.TwipsPerPixelY, pic1.hDC, 0, 0, vbSrcCopy)

To Paint Picture from pic2 to printer
  lRes = BitBlt(Printer.hDC, 0, 0, 1000 / Screen.TwipsPerPixelX, 1000 / Screen.TwipsPerPixelY, pic2.hDC, 0, 0, vbSrcCopy)

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline


Author Comment

ID: 1463105
Thanks clifABB,

I'll give it a shot.  I'm trying the StretchBlt function now, and if that doesn't work I'll try the other one you suggested.  But basically you answered my question and made me realize I need to use the API functions.  And gave me an idea of something to try to boot.

Expert Comment

ID: 1463106
StretchBlt() and BitBlt() are basically the same thing (a lot of the underlying code is mutual between the two).

Also, you may need to set the AutoRedraw property of the picturebox(s) to true

Expert Comment

ID: 1463107
Please show how to create a paintbrush look like program to edit ur bitmap file in VB 4.0 or lower.


Expert Comment

ID: 1463108
You need to post a new question for this, not tack on your request to someone else's question.

Expert Comment

ID: 1463109
please to be showing Photoshop how write filters in QBasic to.

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…

746 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

13 Experts available now in Live!

Get 1:1 Help Now