Click to See Complete Forum and Search --> : Copying pictires
zorcan
August 24th, 2001, 05:46 AM
I'm working on a tool to allow 2 related bitmap images to be aligned to a common datum.
This involves rotating and re-sizing one of them.
My problem is that I am unable to copy the rotated image from one picturebox to another. when I try, I either get an "invalid image" error or - if I have previously loaded an image directly from file into the picturebox in which the rotation is performed, it is that image which gets copied.
Any help would be appreciated.
Cimperiali
August 24th, 2001, 06:47 AM
Look here: it is not directly the answer, but it may help you
http://codeguru.com/cgi-bin/bbs/wt/showpost.pl?Board=vb&Number=55571&page=&view=&sb=
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
The Rater
zorcan
August 24th, 2001, 07:25 AM
Thanks for the help, but this does not seem to address the problem.
From the symptoms, VB doesn't seem to recognise that the image in the picturebox which is being copied has been changed. I know for a fact that it is, because I can view it on the screen.
I'm using the point method to draw each pixel in the source picturebox
zorcan
August 24th, 2001, 07:28 AM
Sorry - I should have said I'm using the pset method to actually draw each pixel.
zorcan
August 24th, 2001, 09:57 AM
Well, I've found a work around, which still leaves me puzzled.
Although the copied image does not reflect the change, I can save it to file, then reload it into the destination picturebox from there.
How come it will save but not copy ??
Another Bill Gates wonder :)
Cimperiali
August 24th, 2001, 10:12 AM
I do not rate you only because I am out of votes... Another way to do it is the following: using a printscreen (you can do this programmatically) to copy the contents on clipboard, and then copy the clipboard contents to the other picturebox.
In any case, your is a nice solution.
Have a nice day
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
The Rater
John G Duffy
August 24th, 2001, 10:15 AM
After drawing the image into the pictureBox do this
Picture1.Picture = Picture1.Image
This creates the Picture from the Image
John G
Cimperiali
August 24th, 2001, 10:24 AM
Great.
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
The Rater
zorcan
August 24th, 2001, 10:35 AM
Yes !!
At last I've stumbled across this myself - I no longer need to save the image first.
Thanks to all of you who've helped here
shree
August 25th, 2001, 12:35 AM
Let's make things a bit more clearer so that you do not stumble later.
A picturebox or form etc have a picture property, and the picture that you assign to it stays permanently in it. For example, even the Cls method doesn't clear this. You must set the picture property explicitly to Nothing to remove this picture.
Above this is a "canvas" on which you can draw upon. The "canvas" is the Image property and it constitutes of the background image as well as any drawing you do on it. Remember that what you draw on it doesn't affect the picture property, only the image property.
If the Autoredraw property is False, then the canvas is directly upon the picture box, so if by any chance, the picturebox gets covered by something else, such as a popup window, then anything you've drawn on it is lost. However, if the Autoredraw property is set, the Image remains as a bitmap in memory, and so is not lost so easily as before.
Whenever you're dealing with the GDI API's, the Image is used, not the picture. But with Visual Basic functions, you can use either. If you're using the PaintPicture method, for example, you can use
Picture2.PaintPicture Picture1.Picture, 0, 0
or
Picture2.PaintPicture Picture1.Image, 0, 0
depending upon which "layer" you want to copy.
Similarly for the SavePicture API. However, the Picture property retains the file format, the image size as well as the resolution whereas the Image property is a bitmap with the resolution the same as the screen, and size as confined by the picturebox.
You can assign the Image property to the Picture property when needed as John suggested.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.