Click here to Skip to main content
16,020,622 members
Please Sign up or sign in to vote.
4.38/5 (3 votes)
See more:
Hello,
i am using following method to create a thumbnail for image stored in SQL table
C#
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

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
 
Share this answer
 
v2
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.
 
Share this answer
 
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!

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