我有一个应用程序,可以拍摄收据并将其上传到远程服务器。
我从相机意图中正确获取了图像的全尺寸照片。我使用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质量)
如何解码图像并在图像视图中显示图像,但不会丢失质量(以及尺寸?)
答案 0 :(得分:1)
显然,您在解码时缩小了图像。
您可能需要删除以下行:
bmOptions.inSampleSize = scaleFactor;