Skip to content

Instantly share code, notes, and snippets.

@nalitzis
Created June 7, 2014 20:46
Show Gist options
  • Save nalitzis/bad4c1e89a0ec185fb0d to your computer and use it in GitHub Desktop.
Save nalitzis/bad4c1e89a0ec185fb0d to your computer and use it in GitHub Desktop.
Subsampling
private void subSampleImage(int powerOf2) {
if(powerOf2 < 1 || powerOf2 > 8) {
Log.e(TAG, "trying to apply upscale or excessive downscale: "+powerOf2);
return;
}
final Resources res = getActivity().getResources();
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = false;
options.inSampleSize = powerOf2;
final Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.brasil, options);
final BitmapDrawable bmpDrawable = new BitmapDrawable(res, bmp);
mRootLayout.setBackground(bmpDrawable);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment