Click here to Skip to main content
14,599,019 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello,
i am using following method to create a thumbnail for image stored in SQL table
public static byte[] MakeThumbnail(byte[] myImage, int thumbWidth, int thumbHeight)
{
    using (MemoryStream ms = new MemoryStream())
    using (Image thumbnail = Image.FromStream(new MemoryStream(myImage)).GetThumbnailImage(thumbWidth, thumbHeight, null, new IntPtr()))
    {
        thumbnail.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
        return ms.ToArray();
    }
}

Reason to create thumbnail : create small size image and reduce download/copy time/

Can i create thumbnail I SQL (something similar to Image.GetThumbnailImage in C#)
For some reason i want to compress images at SQL. Is there any way to it ?
Posted
Updated 4-Jul-13 0:09am
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

No. SQL does not understand images - they are just streams of bytes as far as it is concerned.
Creating a thumbnail means understanding not only the image dimensions, but doing some complex processing on the pixel data as well - you have to "understand" image data properly in order to do it.
   
Comments
Manfred Rudolf Bihy 4-Jul-13 6:39am
   
Countered the 3 vote!
The answer is correct as OP hasn't specified what SQL Server OP is using.
Cheers!
Rate this:
Please Sign up or sign in to vote.

Solution 2

If you're using MS SQL Server >= 2008 you could try your luck with Creating CLR Stored Procedures[^]. Another useful resource is CLR Stored Procedures[^].
It will mean of course that the images will be transferred to the SQL server before being thumbnailed. This will put more load on your network as well as the SQL Server. Not sure if this is what one would want to happen. :)
Caveat!: MSDN writes:

"Note: The ability of SQL Server to execute CLR code is off by default. You can create, alter, and drop database objects that reference managed code modules, but these references will not execute in SQL Server unless the clr enabled Option is enabled by using sp_configure (Transact-SQL)."

Regards,

— Manfred
   
v2

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100