Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


PaintPicture problem

Posted on 1998-06-11
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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.

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


Accepted Solution

clifABB earned 400 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)


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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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 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…
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…
Suggested Courses

610 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