Skip to content

Instantly share code, notes, and snippets.

@sungitly
Last active August 29, 2015 13:57
Show Gist options
  • Save sungitly/9502704 to your computer and use it in GitHub Desktop.
Save sungitly/9502704 to your computer and use it in GitHub Desktop.
Resize bitmap in Android
Bitmap origBitmapOrig = BitmapFactory.decodeFile(imageFilePath);
//Resize the image
double width = origBitmapOrig.getWidth();
double height = origBitmapOrig.getHeight();
int newWidth = 1600
int newHeight = (int)((newWidth/width)*height);
Bitmap newBitmap = Bitmap.createScaledBitmap(origBitmapOrig, newWidth, newHeight, true);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
newBitmap.compress(Bitmap.CompressFormat.JPEG, 95, bos);
InputStream is = new ByteArrayInputStream(bos.toByteArray());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment