Question : Get width and height of JPG-image from database

Hi,

Database field "Photo" contains a JPG-image (SQL Server 2008).
Field Photo's fieldtype = "Image"

Now I want to get the width and height of the stored image.
if Photo = NULL it will be: width = 0 and height = 0
else the actual width and height will be returned.

I prefer not to save the image to a file/stream, or place it in a TImage first. Unless there is no other possibility.

Answer : Get width and height of JPG-image from database

SQL Server 2008 has a capability to, in effect, treat the image as though it were in the database while it is actually managed via a file store.  This gives you the best of both worlds, so to speak.  The process is a little complicated to set up but, once set up, works rather neatly.  You need to look up the FILESTREAM option iun SS2008.  

If you put the image into a VarBinary(MAX) column in your database without the FILESTREAM option, it consumes largish amounts of space in a hury and complicates variaous other aspects of handling the images and data.  

However, if you put the image on a file store and then put the fully UNC pathed filename in the database, you open up a window for the image or the row that links to it being deleted wihtout them both being deleted.  That means you can have orphaned images (due to the row deletion) or broken links (due to the image deletion).

With the FILESTREAM image handling trick available in the SQL Server 2008 database, you can have the image automatically put on a file store with the link being automatically in the database.  If you delete the row in the database, you will delete the image as well.

Technically, I guess, you would still be putting the image into the SQL Server 2008 VarBinary(MAX) column; however the handling is far different.

Random Solutions  
 
programming4us programming4us