Advertisement
Guest User

sample

a guest
Nov 27th, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. public static Bitmap decodeSampledBitmapFromResource(Resources res,
  2.             int resId, int reqWidth, int reqHeight) {
  3.  
  4.         // First decode with inJustDecodeBounds=true to check dimensions
  5.         final BitmapFactory.Options options = new BitmapFactory.Options();
  6.         options.inJustDecodeBounds = true;
  7.         BitmapFactory.decodeResource(res, resId, options);
  8.  
  9.         // Calculate inSampleSize
  10.         options.inSampleSize = calculateInSampleSize(options, reqWidth,
  11.                 reqHeight);
  12.  
  13.         // Decode bitmap with inSampleSize set
  14.         options.inJustDecodeBounds = false;
  15.         return BitmapFactory.decodeResource(res, resId, options);
  16.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement