将位图缩放到80%

Pou*_*ald 4 android image bitmap drawable android-layout

我正在尝试使用缩放位图options.inSampleSize,但据我所知,映射是这样的

  • 如果为inSampleSize1则结果图像为100%

  • 如果是inSampleSize2则结果图像为50%

  • 如果是inSampleSize3那么结果图像是33%

  • 如果是inSampleSize4那么结果图像是25%

  • 如果为inSampleSize5则结果图像为20%

但我想要的是一个80%可扩展的结果图像.我怎么做到的?

Jam*_*ess 12

你能不用这个Bitmap.createScaledBitmap方法?

int srcWidth = srcBitmap.getWidth();
int srcHeight = srcBitmap.getHeight();
int dstWidth = (int)(srcWidth*0.8f);
int dstHeight = (int)(srcHeight*0.8f);
Bitmap dstBitmap = Bitmap.createScaledBitmap(srcBitmap, dstWidth, dstHeight, true);
Run Code Online (Sandbox Code Playgroud)


小智 -1

我认为您可能误解了 inSampleSize 的要点。它的设计目的是节省内存。如果您只是想以 80% 的大小绘制图像,那么您可以在将文件读入内存后使用矩阵来缩小(或放大)它的大小。