Guest User

Untitled

a guest
Apr 26th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. float actualHeight = myImg.Height;
  2. float actualWidth = myImg.Width;
  3. float imgRatio = actualWidth / actualHeight;
  4. float maxRatio = (float)this.Width / this.Height;
  5.  
  6. if(imgRatio!=maxRatio)
  7. {
  8. if (imgRatio < maxRatio)
  9. {
  10. imgRatio = this.Height / actualHeight;
  11. actualWidth = imgRatio * actualWidth;
  12. actualHeight = this.Height;
  13. }
  14. else
  15. {
  16. imgRatio = this.Width / actualWidth;
  17. actualHeight = imgRatio * actualHeight;
  18. actualWidth = this.Width;
  19. }
  20. }
  21. pictureBox.Size=new Size((int)actualWidth,(int)actualHeight);
  22. pictureBox.Location = new Point((int)((this.Width - actualWidth) / 2), (int)((this.Height - actualHeight) / 2));
Add Comment
Please, Sign In to add comment