Solved

Adding/Retrieving Images in Ole Object Fields

Posted on 1998-04-29
8
498 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
Comment Utility
One possible solution:
Use picture/image bound to a data control.
0
 

Author Comment

by:mattyboy
Comment Utility
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
Comment Utility
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
 

Author Comment

by:mattyboy
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 7

Accepted Solution

by:
kamall earned 100 total points
Comment Utility
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
Comment Utility
mattyboy,
What VB version do you have?
0
 
LVL 2

Expert Comment

by:lmorris
Comment Utility
   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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this Micro Tutorial viewers will learn the basic shortcuts and functions in InDesign.
Learn how to set up basic frames and paths in Prezi and understand the open space that Prezi allows you to create presentations in.

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now