I'm trying to resize a bitmap using inDensity
and inTargetDensity
following @colt-mcanlis' instructions explained at 1, 2 and 3.
So far so good, good documentation, great video. The problem is that the resulting sizes for the image makes no sense to me.
For example if I use following values:
srcWidth
is 11774px andsrcHeight
is 6340pxdstWidth
is 1440px anddstHeight
is 2392px
The code I'm using is:
options.inScaled = true;
options.inSampleSize = 8;
options.inDensity = srcWidth;
options.inTargetDensity = dstWidth * 8;
options.inSampleSize;
imageBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.image, options);
And the resulting image has width 70px and height 38px, instead 1440x2393.
I tried without using inSampleSize
, and I get a very similar result. Then I assume the problem is with inTargetDensity
and inDensity
.
I went to the documentation and found the following:
inDensity
int inDensity The pixel density to use for the bitmap...
As far as I know, to calculate a density I need a width, height and a display size but a display size doesn't make sense to me in this context, since I just want to calculate inDensity
and inPixelDensity
independent of a display size.
So, what am I doing wrong here ?