Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save image to file 1

Status
Not open for further replies.

allyeric

Programmer
Mar 14, 2000
104
CA
I would like to know if there is a way to load a picture (image) from a form into a file already created, to be referenced through the database.  For example, the user chooses a file using the common dialog - the picture is sent to an image control, and the picture name gets sent to the database.  I need the actual picture to be saved into a file.  I am sure I am not quite explaining this right, but I hope someone has an idea what I am trying to do with this.  Any suggestions are greatly appreciated!
 
I think you have 2 options:<br><br>1) Use the SavePicture statement to save the actual picture content to a file, and save the filename (from the &quot;open&quot; dialog) in the DB.&nbsp;&nbsp;E.g.<br>&nbsp;&nbsp;&nbsp;&nbsp;SavePicture image1, &quot;filename&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;datacontrol1.recordset(&quot;picfile&quot;) = &quot;filename&quot;<br><br>2) If your DB supports an &quot;object&quot; datatype (the Access DB does), save the picture directly into the DB, e.g.<br>&nbsp;&nbsp;&nbsp;&nbsp;datacontrol1.recordset(&quot;picobj&quot;) = image1.picture<br>If you loaded the &quot;Northwind&quot; sample DB when you installed VB, have a look at the staff table (can't remember its exact name) - it contains photos of the staff.<br><br>Either way (if I remember correctly) in VB 5 you can only save the picture as a .BMP&nbsp;&nbsp;-&nbsp;&nbsp;not sure whether VB 6 allows other formats.<br>
 
thanks for the help.&nbsp;&nbsp;If I save the pictures in the database instead of on the hard drive,wouldn't that cause the program to run alot slower?&nbsp;&nbsp;One of the tables has 98 pictures.&nbsp;&nbsp;There will be others with many more pictures.
 
I can help.<br>VB6 supports bmp, jpg and a few others.. We have a huge catalog where I work.&nbsp;&nbsp;Your database file should contain only the filename (assuming the path is always the same) and keep the pictures in a folder somewhere on the drive.<br><br>If you keep the pictures in a database, the database will be huge, and you'll have to use get chunk and put chunk (assuming SQL Server) to get at them.<br>I emailed Microsoft with this question a few months ago and they save it the same way.(in folders)<br>see: teraserver.microsoft.com<br><br>I hope this helps.
 
thanks bigfoot - thats the understanding I had as well, and thats what I am tring to do.&nbsp;&nbsp;Its fine for a table which already has pictures, but what I am doing is letting the user (an instructor) create a new table(exam), and add pictures to be accessed (by students) at another time.&nbsp;&nbsp;I tried Philcha's suggestion (the first one), and am getting no errors, but its not saving the picture at all. And, I would like the picture to be saved into a certain file, can that be done at design time?&nbsp;&nbsp;Or does it automatically get saved to the app path?
 
You can bury any path you want into the filename and it'll put it there.&nbsp;&nbsp;It should save the picture.&nbsp;&nbsp;I do it when mu users want a copy of the pictures from the database.
 
uh oh - now I have another problem with it.&nbsp;&nbsp;It saves the first image I use to the correct path, but any others I save get saved to C:\Windows\Recent folder.&nbsp;&nbsp;When I debug, the program follows exactly the same path.&nbsp;&nbsp;First picture goes into a file on the D drive (which is correct).&nbsp;&nbsp;Why would the others be saved elsewhere?&nbsp;&nbsp;I just don't understand ....<br><br>
 
Are you storing the full path, or are you relying on relative paths? ie.<br><br>d:\myimages\company\producta.jpg<br><br>or<br>.\company\producta.jpg<br><br>Chip H.<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top