【发布时间】:2017-09-27 12:07:11
【问题描述】:
我有一个应用程序可以拍摄收据照片并将其上传到远程服务器。
我从相机意图中正确获取了图像的全尺寸照片。我使用 Google 开发人员中的官方文档进行了操作。
然后我将我的图片设置为这样。
private void setPic() {
// Get the dimensions of the View
int targetW = imageView.getWidth();
int targetH = imageView.getHeight();
// Get the dimensions of the bitmap
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = true;
BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
int photoW = bmOptions.outWidth;
int photoH = bmOptions.outHeight;
// Determine how much to scale down the image
int scaleFactor = Math.min(photoW/targetW, photoH/targetH);
// Decode the image file into a Bitmap sized to fill the View
bmOptions.inJustDecodeBounds = false;
bmOptions.inSampleSize = scaleFactor;
bmOptions.inPurgeable = true;
Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
//Bitmap bitmap = null;
//try
//{
//bitmap = MediaStore.Images.Media.getBitmap(getContentResolver() , //Uri.parse(mCurrentPhotoPath));
//}
//catch (Exception e)
//{
//handle exception
//}
imageView.setImageBitmap(bitmap);
new ImageSaver(getApplicationContext()).
setFileName("currentImage.png").
setDirectoryName("Android_Upload").
save(bitmap);
Model.currentImage = "currentImage.png";
}
在设备上查看时效果很好。但是在将其发送到服务器并从那里查看后,图像尺寸太小了。
ImageSaver 类几乎可以将图像保存在其他地方并对其进行压缩,但 png 的质量为 100。我这样做了,因此我可以稍后将数据库中的图像作为 Blob(再次以 100 质量)
如何解码图像并在图像视图中显示图像,但又不损失质量(和大小?)
【问题讨论】:
-
您要保存全尺寸照片吗?
-
@Audi 是的,我想要全尺寸的照片。我目前拥有的图像是全尺寸照片。但是为了避免内存泄漏,我使用了 set pic。