Simple example:
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inSampleSize = scale;
Bitmap bmp = BitmapFactory.decodeStream(is, null, opts);
When I’m passing scale value not equal to power of two, bitmap is still scaled by closest power of 2 value. For example, if scale = 3 then actual scale become 2 for some reason. Maybe it’s because I’m using hardware acceleration?
Anyway, how can I scale bitmap by non power-of-2 value without allocation memory for full bitmap?
P.S. I know, that using power of two is much faster, but in my case time isn’t such critical and I need image scaled exactly by provided scale (otherway it’s become too big or too small) – I’m woking with image processing, so big image itself not such a problem (ImageView scales it to required size), but it takes extra time to apply some filter for example.
If you read the documentation for
inSampleSize:You are not guaranteed exact dimensions. Since memory sounds like it is a concern, I would use your current method to get the image to larger than what you need but something that fits better with your memory requirements than the source image. Then use a different method like
Bitmap.createScaledBitmapto get it to your exact dimensions.