Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

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

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
ckvkkeek
Asked:
ckvkkeek
  • 4
  • 4
1 Solution
 
AxterCommented:
>>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
 
ckvkkeekAuthor Commented:
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
 
ckvkkeekAuthor Commented:
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
Industry Leaders: 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!

 
AxterCommented:
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
 
AxterCommented:
Correction:
What I did instead was stored each image images in a unique filename.
0
 
ckvkkeekAuthor Commented:
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
 
AxterCommented:
>>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
 
ckvkkeekAuthor Commented:
Fully aware.  And we will document and warn users because of these limitations.

Thanks.
ck
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now