Scale Down Images in C#

1) open a file stream
        FileStream fs = File.OpenRead(fullImgPath);
2) load the image
        Image fullImg = Image.FromStream(fs);
3) define the new height
        int thHeight = Convert.ToInt32(ConfigurationManager.AppSettings["thumbHeight"]);
4) define a callback function when thumbnail abort
        Image.GetThumbnailImageAbort dummyCallback=new Image.GetThumbnailImageAbort(ThumbnailCallback);
5) set the new height and width of the image using GetThumbnailImage function
        Image thumbImg = fullImg.GetThumbnailImage((int)(fullImg.Width * thHeight) / fullImg.Height, thHeight, dummyCallback, IntPtr.Zero);
6) save the thumb image
        thumbImg.Save(thumbImgpath);
7) dispose
        thumbImg.Dispose();

8) the call back function implementation
public static bool ThumbnailCallback() { return false; }

Comments

Popular posts from this blog

Log4Net Different files in the same assembly

ටෙස්ලා

Setup Test automation with Selenium and Ruby