PictureSelector
PictureSelector copied to clipboard
裁剪预览时 分辨率低的图片再次被压缩,图片模糊
当前使用的版本是多少?
2.7.3-rc09
Demo能否复现这问题?
能
描述问题或提供错误log?
相册选择图片后开始裁剪,点击右边的确定,图片非常模糊,点击左边的预览,图片还是清晰的。
查看源码,BitmapLoadTask#doInBackground中有一段代码如下所示:
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
if (options.outWidth == 0 && options.outHeight == 0) {
options.inSampleSize = BitmapLoadUtils.calculateInSampleSize(mInputImageWidth, mInputImageHeight, mInputImageWidth, mInputImageHeight);
} else {
options.inSampleSize = BitmapLoadUtils.calculateInSampleSize(options.outWidth, options.outHeight, mRequiredWidth, mRequiredHeight);
}
options是new出来的,所以肯定走第一个if,在里面的代码:
public static int calculateInSampleSize(@NonNull int width,int height, int reqWidth, int reqHeight) {
// Raw height and width of image
int inSampleSize = 1;
if ((width == 0 && height == 0) || (width == reqWidth && height == reqHeight)) {
return inSampleSize * 2;
}
if (height > reqHeight || width > reqWidth) {
// Calculate the largest inSampleSize value that is a power of 2 and keeps both
// height and width lower or equal to the requested height and width.
while ((height / inSampleSize) > reqHeight || (width / inSampleSize) > reqWidth) {
inSampleSize *= 2;
}
}
return inSampleSize;
}
默认是1,同时因为上面宽高是0,0所以直接走第一个,采样率直接就是2了。导致图片模糊了。 手动将采样率改为1,图片就是清晰的。
但是我们的项目因为某种原因,不方面下载源码下来修改,所以这块就自己处理不了了。同时版本3+暂时不方便使用