Picture in Database

Hi All,
I wonder if someone can help me and direct me in the right place. I am looking to write an app that uses pictures from a database but i dont want to save them into the database but instead in a folder on the computer . So what I want to do is to save the path of the pictrure into the database and then when someone clicks on that record the picture is populated into a canvas or imagewell. Can someone point me in the right direction.


I assume you know how to save a picture to and read it from a file, so look into FolderItem.GetSaveInfo. That will act like an alias so it should be able to find the relative path even on a different drive.

Thanks… Yes I know how to read a picture so will have a play. Not sure how to use GetSaveInfo but will figure something out

What do you want to achieve chris? Could you save the pic in the database or are you looking at browsing a folder and opening pictures? Can you give some more detail as it sounds like you know what to do so your problem is not clear…

You could base64 encode the image and save it in the database, that way you don’t have to keep track of all that GetSaveInfo data…

dim saveInfo as String = myPictureFolderItem.GetSaveInfo( nil, 0 )
saveInfo = EncodeHex( saveInfo ) // to be on the safe side

// Now save saveInfo to your database.
// Later…

dim saveInfo as String = GetSaveInfoFromDB()
saveInfo = DecodeHex( saveInfo )
dim myPictureFolderItem as new FolderItem( saveInfo ) 

Instead of hex or base64 encoding couldn’t the memoryblock which contains the picture (picture.getdata) be stored, as is, in an SQL Blob column? (Binary Large OBject)… Thus reducing hex/base64 encoding overhead? … At least that’s what I do. Then when it comes time to re-assimilate the image it can be read straight into picture.fromdata (memoryblock) with no decodebase64/decodehex which adds a miniscule amount of time to perform the operation. …but really noticable amount of time if performing the action numerous times consecutively (ie adding/creating a directory of images).

Thanks all. I wanted to save the pictures to the database but I think it may make the database really large if they are saved in the database… So I thought maybe save them to the disk instead. What do most people do ? what is the best practise on this.

Well, in a db you don’t have to worry about images being misplaced, later causing undesirable results in your program. If it’s a piece of software that you will distribute or may need to clone, a db would be best. There’s pros and cons to both, but IMHO db would be best. … less chance of hitting a “snag” down the road when one image comes up missing. :slight_smile:

Store it in the DB.

What’s the difference? A picture takes up disk space if stored on its own whereas storing it in the DB adds the disk space there.

Also, I agree with Matthew, at least it’s not possible to lose the file (if it’s deleted etc.).

I concur.

[quote=85709:@Simon Berridge]What’s the difference? A picture takes up disk space if stored on its own whereas storing it in the DB adds the disk space there.

With SQLite, you’ll get much better performance keeping large objects in their own files. Depends on the database.

You could even use a plugin or a zip class to compress the image in place of base64encode/hexencode (which increases binary size by at least a 3rd) :slight_smile: then if you had 1024 1MB images that took 1GB of space, it would only make a ~300MB Database in place of a 1GB one. …

millions of ways to skin a cat… (I don’t skin cats :-p)

One major problem with storing pictures in the db is that you end up having huge db-backup files. It really depends on how much picture data you expect.

If you do go the route of storing them in the database (which I have done), then create a separate table just for the image files with minimal data (e.g. file name, file binary data, file creation date, file modification date, Mac codes, etc.) and use a key to that record in your related table.