Advertisement
lilo_booter

Scaling to preserve aspect ratio and centering

Mar 19th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. int src_w = 1000;
  2. int src_h = 1000;
  3. int dst_w = 595;
  4. int dst_h = 824;
  5.  
  6. int letter_h = ( dst_w * src_h ) / src_w;
  7. int pillar_w = ( dst_h * src_w ) / src_h;
  8.  
  9. result.h = dst_h;
  10. result.w = pillar_w;
  11.  
  12. if ( result.w > dst_w )
  13. {
  14. result.w = dst_w;
  15. result.h = letter_h;
  16. }
  17.  
  18. result.x = ( dst_w - result.w ) / 2;
  19. result.y = ( dst_h - result.h ) / 2;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement