Save Images to files

chenlin1025
02-21-2005, 09:48 PM
Hi!
I have problems saving images into files. These images are drawn inside a picture box during run time. When I tried to use SavePicture method , all I can see is the picture box's picture. The images are not captured along with the picture box. Any advice?
Thanks!

chenlin1025
02-23-2005, 12:01 AM
HI~Thanks for your quick reply..So sorry to tell u this..I have posted my question in the wrong section. I'm using VB 6.0 instead of VB.net. So, is your solution still applicable to my problem?

OnErr0r
02-23-2005, 12:16 AM
Not really, unless you want to use GDI+, which is possible, but not really necessary if you just want to save to a BMP.

SavePicture Picture1.Image, "c:\foo.bmp"

chenlin1025
02-23-2005, 12:36 AM
I have tried this method but all I get is a blank picture without any images. My graphical plot consists of a group of predefined images loaded inside a picture box.How can I save all the images together with the picture box? Is it possible to link the images to the picture box??

OnErr0r
02-23-2005, 08:55 AM
I have tried this method but all I get is a blank picture without any images. My graphical plot consists of a group of predefined images loaded inside a picture box.How can I save all the images together with the picture box? Is it possible to link the images to the picture box??

Describe how you are currently displaying/loading images into the picturebox. There is no "link" per se. You can load images at runtime with the LoadPicture function or draw them with PaintPicture. Images can be loaded at design time by selecting them via the picture property.

jcmatt
02-23-2005, 10:45 AM
Try Picture1.Picture = Picture1.Image before saving.

passel
02-23-2005, 09:09 PM
Make sure you have AutoRedraw set to True on your picturebox. Then OnErrOr's SavePicture suggestion should work.

chenlin1025
02-24-2005, 12:49 AM
Thanks a lot, guys....but i am still waiting for my answers. Yes, I have loaded the pictures by using the LoadPicture method. Unfortunately, the 'SavePicture Picture1.Image, "c:\foo.bmp" ' method does not solve my problem. The image saved is the background picture without any images plotted during run time.

chenlin1025
02-24-2005, 12:51 AM
I have quite a number of images drawn in the picture box. How can I combine and save these images into one picture file?

jcmatt
02-24-2005, 07:24 AM
Don't do this:
'SavePicture Picture1.Image, "c:\foo.bmp" '

Do this:
'Picture1.Picture = Picture1.Image'
'SavePicture Picture1.Picture, "c:\foo.bmp" '

Jim

OnErr0r
02-24-2005, 08:54 AM
There is a reason to use AutoRedraw = True. If you want plotted pixels or drawn images to persist, you will want to use AutoRedraw = True. If you do not use it, when your form is minimized or partially obsured, when it is visible again the drawn pixels or images will be gone.

An alternative to AutoRedraw = True is drawing persistant images in the picturebox paint event. However, that can add some complexity to your drawing operations.

Find attached a test project using AutoRedraw:

passel
02-24-2005, 06:43 PM
Don't do this:
'SavePicture Picture1.Image, "c:\foo.bmp" '

Do this:
'Picture1.Picture = Picture1.Image'
'SavePicture Picture1.Picture, "c:\foo.bmp" '

Jim

Copying the .Image to the .Picture and then saving the .Picture will only do you
any good if AutoRedraw is set to True, otherwise the only thing in the .Image
is a copy of what was in the .Picture to start with.

The picture in the .Picture property is automatically copied to the .Image
buffer, and if AutoRedraw is set True, your drawing is done in the .Image buffer
as well.

So (if AutoRedraw is True), you can copy the .Image back to the
.Picture, with your drawing and save the .Picture.
BUT since you have to have AutoRedraw set to True, there is no need to first
copy the .Image to the .Picture and then save the .Picture, just save the .Image.

jcmatt
02-25-2005, 10:39 AM
passel,

True. I've always done it my way with AutoRedraw=True being a given.

Jim

passel
02-25-2005, 11:05 AM
Another advantage to not copying the .Image to the .Picture (besides being unnecessary)
is that if you had a complicated background and were going to be generating some
frames (like oldstyle cartoon animation cells), you could draw characters on top of the
background, save the .Image with the combind graphics, then use .Cls to clear the
characters, but not affect the background. You could then draw the characters in a
new position and save the next frame, erase them, and repeat.

If you copy .Image to .Picture, you've now made the characters a permanent part of
the .Picture, and you would have to reload your picture to "erase" the characters.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum