Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
while retrieving icon image from database in asp.net to show leftside in treeview , the icon image is showing so large . so, how to reduce width of icon image?
Posted
Comments
Sushil Mate 12-Jul-13 6:47am    
why you saving the large image in the db when you want just a thumbnail.

Found on StackOverFlow.

http://stackoverflow.com/a/13977707[^]

C#
public static Bitmap CreateThumbnail(Bitmap source, int thumbWidth, int thumbHeight, bool maintainAspect)
{
        if (source.Width < thumbWidth && source.Height < thumbHeight) return source;

        Bitmap image = null;
        try
        {
            int width = thumbWidth;
            int height = thumbHeight;

            if (maintainAspect)
            {
                if (source.Width > source.Height)
                {
                    width = thumbWidth;
                    height = (int)(source.Height * ((decimal)thumbWidth / source.Width));
                }
                else
                {
                    height = thumbHeight;
                    width = (int)(source.Width * ((decimal)thumbHeight / source.Height));
                }
            }

            image = new Bitmap(width, height);
            using (Graphics g = Graphics.FromImage(image))
            {
                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                g.FillRectangle(Brushes.White, 0, 0, width, height);
                g.DrawImage(source, 0, 0, width, height);
            }

            return image;
        }
        catch
        {
            image = null;
        }
        finally
        {
            if (image != null)
            {
                image.Dispose();
            }
        }

        return null;
}
 
Share this answer
 
while retrieving icon image from database in asp.net to show leftside in treeview , the icon image is showing so large . so, how to reduce width of icon image?
 
Share this answer
 
Comments
Sushil Mate 12-Jul-13 7:21am    
check my solution.

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