Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. private Bitmap scaleImage(Resources res, int id, int lessSideSize) {
  2. Bitmap b = null;
  3. BitmapFactory.Options o = new BitmapFactory.Options();
  4. o.inJustDecodeBounds = true;
  5.  
  6. BitmapFactory.decodeResource(res, id, o);
  7.  
  8. float sc = 0.0f;
  9. int scale = 1;
  10. // if image height is greater than width
  11. if (o.outHeight > o.outWidth) {
  12. sc = o.outHeight / lessSideSize;
  13. scale = Math.round(sc);
  14. }
  15. // if image width is greater than height
  16. else {
  17. sc = o.outWidth / lessSideSize;
  18. scale = Math.round(sc);
  19. }
  20.  
  21. // Decode with inSampleSize
  22. BitmapFactory.Options o2 = new BitmapFactory.Options();
  23. o2.inSampleSize = scale;
  24. b = BitmapFactory.decodeResource(res, id, o2);
  25. return b;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement