Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have some images stored in the sql server database and i am displaying the images in their original size at the moment. But i want to resize the images so that they load faster over internet. Want to know how can i do this?
I came across this CLICK HERE[^] But i am not sure if this will work in case of images stored in varbinary format in sql server database.
Posted

1 solution

The question can be split in two parts: 1) how to store/retrieve images to/from database? 2) how to resize images (this is called resampling)? The basic answer is: you should take the two separately. Retrieve an image, resample it (you can do it on the fly, without storing images in temporary files), store it again.

As to the first part, honestly, it's not good to answer a question which has been asked and answered so many times: http://www.codeproject.com/search.aspx?q=database+%28image+OR+images+OR+bitmap+OR+bitmaps%29+C%23&doctypeid=5[^].

As to resampling: you can use System.Drawing. Please see my past answers for further detail:
resize image in vb.net[^],
Read Big Tiff and JPEG files (>(23000 x 23000) pix) in a stream. And display part of it to the screen in realtime.[^].

[EDIT]

I did not want to say that storing resample images back in the database is a must. You can store additional versions of images, of smaller sizes, or you can not change the database at all but resample images on the fly on each request, only when you need to display them.

—SA
 
Share this answer
 
v3
Comments
arbaaz jalil 20-Aug-13 12:07pm    
I began description of my question with "I have some images stored in the sql server database" which indicates that i already know how to store them into database.
Sergey Alexandrovich Kryukov 20-Aug-13 12:32pm    
Good for you.
I wasn't quite obvious, because "I have some images stored" does not imply you know how to do it. The "I'm not sure" part of your question suggest that there is something you still don't know (the answer is: yes, of course you can do it with images stored as varbinary).

And it does not compromise my answer at all. I answered in full, please either accept it formally (green button) or ask your follow-up questions.
However, your follow-up questions will be welcome anyway.
—SA
fjdiewornncalwe 20-Aug-13 12:29pm    
+5 for a complete solution.
Sergey Alexandrovich Kryukov 20-Aug-13 12:33pm    
Thank you, Marcus.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900