What is the best way of resizing a bitmap?
Using
options.inSampleSize = 2;
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.mandy_moore, options);
or
Bitmap resizedbitmap = Bitmap.createScaledBitmap(bitmap, 200, 200, true);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It depends the flexibility you need:
options.inSampleSize = N;means that you will obtain an image which is N times smaller than the original. Basically, the decoder will read 1 pixel every N pixel.Use that option if you don’t need a particular size for your bitmap but you need to make it smaller in order to use less memory. This is particularly useful for reading big images.
Bitmap.createScaledBitmapon the other hand give you more control: you can indicate precisely the final dimension of the bitmap, …The best is to use a combination of both method:
inSampleSizeyou can use to decode the source image efficiently (such that the decoded image is still bigger than the final size you need)Bitmap.createScaledBitmapto precisely control the resulting size