Solved

Adding/Retrieving Images in Ole Object Fields

Posted on 1998-04-29
8
505 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Add visuals to your Prezi to keep your audience engaged. Learn how to embed images, edit them, and more in this video micro tutorial. Select "Insert" from the top menu in your Prezi editor: Select "Image": A toolbar will pop in from the right …
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.

688 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