Solved

Adding/Retrieving Images in Ole Object Fields

Posted on 1998-04-29
8
503 Views
Last Modified: 2013-11-25
I need to store images (jpg, gif, bmp, whatever) in Ole Object fields (Long Binary) in an MS Access table.  I am able to add an image via Access, however I cannot retrieve the image thru VB.

I need to be able to add several images from the Table to an ImageList control for use by items in a ListView control.

I tried using the GetChunk method and FieldSize property for the Field, but am having little luck.

Any suggestions?
0
Comment
Question by:mattyboy
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 2

Expert Comment

by:marti
ID: 1434488
One possible solution:
Use picture/image bound to a data control.
0
 

Author Comment

by:mattyboy
ID: 1434489
I have tried that already.  I get error 481 "Invalid Picture".  I have tried using icons, bitmaps, wmf files, jpgs, gifs, you name it.

mattyboy
0
 
LVL 2

Expert Comment

by:lmorris
ID: 1434490
If you store an image as an OLE object in a database, then it's now an OLE object, not an image. What is stored in the database is some header information then the object information. So, if you stored an image in a database as an OLE object, then you must use the OLE control to display that image. Not an image or picture control.

To demonstrate, place the ole control on your form. It will bring up a dialog box asking a couple of questions, just click cancel.

Next, place a data control on the form. Set the databasename to your northwinds database. Mine is located in "C:\Program Files\DevStudio\VB\Nwind.mdb"

Set the recordsource to Employees.

Click on the OLE control and set it's datasource to Data1. Set it's datafield to photo.

Run the program and see your images.

If you want to convert the ole object back to an image, you'll need to strip off the OLE information at the begining of the file. Unfortunatly, I don't remember how many bytes that is.

Another alternative, is not to save the images in an OLE field. If I was using SQL Server, I would store it in a varbinary field.

And finally, the winning solution, is not to store images in a database at all. Store the image to a file, then just place the directory path and filename in the database. This has the advantages of keeping your database small/quick and allows you to easily work with the file.

If you have anyother question, just email me at lmorris@booksarefun.com
0
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!

 

Author Comment

by:mattyboy
ID: 1434491
Well, I need to put the images into an ImageList control.  I already know how to display the image from the Field using a data aware OLE Control.

I cannot use the path as a "pointer" to the image, because the database file is "mobile", and I cannot transport a bunch of images with it.  There are not that many images, so speed/size isn't really even an issue.

Ideally, I need to be able to load the image into an Image or PictureBox Control so I can add it to the ImageList, or be able to add it to the ImageList control directly.

If you can remember how to extract the image file from the field, please let me know, and I will more than gladly award you the points for the question!

mattyboy
0
 
LVL 7

Accepted Solution

by:
kamall earned 100 total points
ID: 1434492
mattyboy,
I had developed a project sometime ago that shows pictures stored in an access database into a picture box. If this solves your problem, comment me your e-mail address so I can send it to you. If not, please feel free to reject my answer.
Best regards
0
 
LVL 7

Expert Comment

by:kamall
ID: 1434493
mattyboy,
What VB version do you have?
0
 
LVL 2

Expert Comment

by:lmorris
ID: 1434494
   Dim db As Database
    Set db = DBEngine(0).OpenDatabase("NWind.mdb")
   
    Dim rs As Recordset
    Set rs = db.OpenRecordset("Employees")
   
    Dim lFileLength As Long
    lFileLength = rs.Fields("Photo").FieldSize
   
    Dim bChunk() As Byte
    ReDim Chunk(lFileLength)
   
    bChunk() = rs!photo.GetChunk(78, lFileLength)
   
    Dim lDataFile As Long
    lDataFile = FreeFile()
   
    Open "pictemp.bmp" For Binary Access Write As lDataFile
        Put lDataFile, , bChunk()
    Close lDataFile

    Image1.Picture = LoadPicture("pictemp.bmp")

0
 

Author Comment

by:mattyboy
ID: 1434495
kamall,
sorry it's been so long since i've visitted this site!  if you can still help me, i really could use the help!  my e-mail address is mattyboy@luckydevil.com

thanks!

matty

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
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…
It’s easy to embed any of your public Prezi presentations on your website or social network to share with others. Learn how simple it is in this tutorial.

762 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