Guest User

Untitled

a guest
Feb 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. private void GenereMiniature(Stream st, string directory, string filename, int Height)
  2. {
  3. Bitmap thumbIndex = new Bitmap(st);
  4. int oldWidth = thumbIndex.Width;
  5. int oldHeight = thumbIndex.Height;
  6.  
  7. double coeff = Convert.ToDouble(oldWidth) / Convert.ToDouble(oldHeight);
  8.  
  9. int newHeight = Height;
  10. int newWidth = Convert.ToInt32(newHeight * coeff);
  11.  
  12. Size ThumbnailsSize = new Size(newWidth, newHeight);
  13. Image oImg = Image.FromStream(st);
  14. Image oThumbNail = new Bitmap(ThumbnailsSize.Width, ThumbnailsSize.Height);
  15. Graphics oGraphic = Graphics.FromImage(oThumbNail);
  16. oGraphic.CompositingQuality = CompositingQuality.HighQuality;
  17. oGraphic.SmoothingMode = SmoothingMode.HighQuality;
  18. oGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
  19.  
  20. Rectangle oRectangle = new Rectangle(0, 0, newWidth, newHeight);
  21. oGraphic.DrawImage(oImg, oRectangle);
  22. oGraphic.Dispose();
  23. oImg.Dispose();
  24.  
  25. oThumbNail.Save(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, directory + filename));
  26. }
Add Comment
Please, Sign In to add comment