Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

PaintPicture problem

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
0
jamespaul
Asked:
jamespaul
  • 3
  • 3
  • 2
  • +1
1 Solution
 
zsiCommented:
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?

0
 
jamespaulAuthor Commented:
zsi,
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.
0
 
jamespaulAuthor Commented:
Whoops, not a function.  I tried the vbSrcCopy with the paintpicture, but alas, to no avail.
Thanks for the suggestion.
0
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.

 
clifABBCommented:
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)

0
 
jamespaulAuthor Commented:
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.
0
 
clifABBCommented:
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
0
 
winsumpuCommented:
Please show how to create a paintbrush look like program to edit ur bitmap file in VB 4.0 or lower.


0
 
clifABBCommented:
winsumpu:
You need to post a new question for this, not tack on your request to someone else's question.
0
 
zsiCommented:
please to be showing Photoshop how write filters in QBasic to.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now