?
Solved

How to add image to Access DB in C++ (not as Long Binary)

Posted on 2005-03-25
8
Medium Priority
?
241 Views
Last Modified: 2010-04-01
I find all kinds of examples to add an image to a database as a long binary, but I want to add it to the database so when the user opens up their access form the image displays correctly.

I have searched for days, and can't find a solution.

Thanks for the help.
0
Comment
Question by:ckvkkeek
[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
  • 4
  • 4
8 Comments
 
LVL 30

Accepted Solution

by:
Axter earned 2000 total points
ID: 13639031
>>so when the user opens up their access form the image displays correctly.
To do this, you have to add the object as an embedded OLE object to the Access database.

That means before writing the raw image data, you need to write embedded OLE header and associated data.

See following CodeGuru link:
http://www.codeguru.com/Cpp/data/mfc_database/microsoftaccess/article.php/c1123/
0
 
LVL 1

Author Comment

by:ckvkkeek
ID: 13639295
I think thats it!

Let me take a look at this on Monday and if it works (and I am assuming it will), you will get yourself a fat 500 points!

ck
0
 
LVL 1

Author Comment

by:ckvkkeek
ID: 13673024
That did it.  I just added an image and it showed up as a "PhotoShop" image.  This was much harder than I ever thought it would be.  The sample given on that page isn't very good, but if you can put it all together it does work.
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!

 
LVL 30

Expert Comment

by:Axter
ID: 13673187
I recently had a similar requirement for adding images to a MS Access database, however, it slow things down so much, I had to giveup the idea.

What I did instead was stored all the images in a unique filename.  And then I added a field in the record that had the name of the file.

I was still able to view the image in my form by adding the following code:

Private Sub Form_Current()
Dim strMyString As String

strMyString = Replace(CurrentDb.Name, Dir(CurrentDb.Name), Me![Signature])
Me![SignerImage].Picture = strMyString

End Sub

In above code Me![Signature] is the field that has the filename only (or a filename and a subdirectory)

The code creates a full path by using CurrentDb.Name to determine the *.MDB file location and adding that to the value of Me![Signature] field.

Then it sets the IMAGE control field via Me![SignerImage].Picture (where SignerImage is the name of the Image control field).

This runs much faster, and the image can be any recognised MS Access image (bmp, gif, PNG, etc....)

Thanks for the points and the A grade.
0
 
LVL 30

Expert Comment

by:Axter
ID: 13673195
Correction:
What I did instead was stored each image images in a unique filename.
0
 
LVL 1

Author Comment

by:ckvkkeek
ID: 13673356
Well I will use this other info as well.

I am adding a feature to my companies Scanning SDK, and I am going to offer them the ability to store images in an Access database.  I plan on giving them 3 options:
1. Store as an image that will display (my original question).
2. Store as a long binary, and provide them with code to decipher this out to a viewable image.
3. Store as a link and provide them with the code to add the image to their form (your second answer).

I am sure you are aware of the drawbacks to each, so I want to let the user choose.
0
 
LVL 30

Expert Comment

by:Axter
ID: 13673488
>>I am sure you are aware of the drawbacks to each, so I want to let the user choose.

FYI:
MS Access has a 2-Gigabyte file size limit.  Actually I think this limit is associated more with the OS file size limit.

I'm not sure how many images you plan to store, or what are the size of the images, but this is something else to consider.

With my requirement, we have 250,000 records and each image is 110KB.
If I had tried to store the images in the Database, it would have taken 27-Gigabyte, which is way pass the file size limit.

If you only have about 10,000 records or less, and the images are less then 110KB, then you shouldn't have a problem.
Otherwise, you should calculate predicted record maximum with the size of the average image, to make sure you don't come close to reaching the max file size.

If you store the OLE object instead of raw image, you also have to account for additional space for OLE header data.
0
 
LVL 1

Author Comment

by:ckvkkeek
ID: 13673618
Fully aware.  And we will document and warn users because of these limitations.

Thanks.
ck
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

771 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