Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. ublic static Bitmap ChangeSize(this Bitmap bitmap, int height, double proportion)
  2. {
  3. if (Math.Abs(1-proportion)<double.Epsilon)
  4. {
  5. var newWidth = bitmap.Height / height * bitmap.Height;
  6. return bitmap.ChangeSize(newWidth,height);
  7. }
  8. var width = (int)(bitmap.Height * proportion);
  9. var middle = bitmap.Width / 2;
  10. var margin = (middle - (width /2));
  11.  
  12. return bitmap.Clone(
  13. new System.Drawing.Rectangle(margin, 0, width, bitmap.Height),
  14. bitmap.PixelFormat);
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement