在我的应用程序中,我加载了每个可绘制对象并将其保存在手机内存中,但是当我执行此过程时,所有可绘制对象都变为大分辨率:
压缩前: 可绘制对象上的 FileA.PNG:423x101; 9,52Ko
压缩后: SD 卡上的 FileA.PNG:1269x303; 89,36Ko
你知道压缩后如何保持(之前)的分辨率吗? 我尝试使用 JPEG,但结果相同。
public void SaveImage(int resId){
Bitmap bmp = BitmapFactory.decodeResource(getResources(), resId);
try {
OutputStream fOut = null;
File file = new File(Environment.getExternalStorageDirectory() + File.separator + "Folder", getResources().getResourceEntryName(resId)+".PNG");
file.createNewFile();
fOut = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.PNG, 100, fOut);
fOut.flush();
fOut.close();
MediaStore.Images.Media.insertImage(this.getContentResolver(), file.getAbsolutePath(), file.getName(), file.getName());
} catch (Exception e) {
}
}
你能给我一个线索吗?
谢谢,
最佳答案
如果您将图像存储在 drawable
文件夹中,它们会根据您设备的分辨率自动缩放,从而产生不同的尺寸。
您需要将它们存储在文件夹 drawable-nodpi
中,或者在 raw
或 assets
中的某个地方。
关于java - 在位图压缩时保留图像的分辨率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52600172/