.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Articles >> ASP.NET >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Create thumbnail of a Image

Posted By:Lakhan Pal Garg       Posted Date: June 30, 2010    Points: 25    Category: ASP.NET    URL: http://www.dotnetspark.com  

Create thumbnail of a Image

Pass three arguments:

(1) Image To Scale
(2) Desired height of the output image
(3) Desired width of output image

Here is the Code to create thumbnail:

/// Scales an image as per the ratio of dimensions of the image to hight and width specified in the 
        /// parameters
        public static System.Drawing.Image ScaleByPercent(string strImage, double dblImgHt, double dblImgWd)
            Bitmap imgRetPhoto = null;
            double dblWdRatio, dblHtRatio;

                imgRetPhoto = new Bitmap(strImage);
                if (imgRetPhoto.Height > Convert.ToInt32(dblImgHt) || imgRetPhoto.Width > Convert.ToInt32(dblImgWd))
                    if (imgRetPhoto.Height > dblImgHt)
                        dblHtRatio = dblImgHt / Convert.ToDouble(imgRetPhoto.Height);
                        dblWdRatio = Convert.ToDouble(imgRetPhoto.Width) * dblHtRatio;
                        imgRetPhoto = new Bitmap(imgRetPhoto, Convert.ToInt32(dblWdRatio), Convert.ToInt32(dblImgHt));
                        imgRetPhoto.SetResolution(imgRetPhoto.HorizontalResolution, imgRetPhoto.VerticalResolution);

                    if (imgRetPhoto.Width > dblImgWd)
                        dblWdRatio = dblImgWd / Convert.ToDouble(imgRetPhoto.Width);
                        dblHtRatio = Convert.ToDouble(imgRetPhoto.Height) * dblWdRatio;
                        imgRetPhoto = new Bitmap(imgRetPhoto, Convert.ToInt32(dblImgWd), Convert.ToInt32(dblHtRatio));
                        imgRetPhoto.SetResolution(imgRetPhoto.HorizontalResolution, imgRetPhoto.VerticalResolution);
                    return imgRetPhoto;
                    return imgRetPhoto;
            catch (Exception ex)
                throw ex;
 Subscribe to Articles


Further Readings:

Author: jessica         Company URL: http://www.dotnetspark.com
Posted Date: July 13, 2010

Hi all

Thumbnail images are very small (viewing and file) size images i.e. they are resized images that are not only small physical size but small file size. Real thumbnails are NOT just images that loog smaller because the are being resized with the width and height attributes of the img tag.

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend