Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 KB | None | 0 0
  1.         private void resizeImage(string imgPath, string newPath, int Height)
  2.         {
  3.             FileStream fs = new FileStream(imgPath, FileMode.Open, FileAccess.Read);
  4.             Image imgToResize = Image.FromStream(fs);
  5.             fs.Close();
  6.             int sourceWidth = imgToResize.Width;
  7.             int sourceHeight = imgToResize.Height;
  8.  
  9.             float nPercent = 0;
  10.             float newWidth;
  11.  
  12.             nPercent = ((float)Height / (float)sourceHeight);
  13.             newWidth = ((float)sourceWidth * nPercent);
  14.  
  15.             Bitmap b = new Bitmap((int)newWidth, Height);
  16.             Graphics g = Graphics.FromImage((Image)b);
  17.             g.InterpolationMode = InterpolationMode.HighQualityBicubic;
  18.  
  19.             g.DrawImage(imgToResize, 0, 0, newWidth, Height);
  20.             g.Dispose();
  21.  
  22.             imgToResize.Save(newPath);
  23.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement