我有这台机器,我必须捕获产品的图像并填充其他数据以将它们上载到服务器。我一直在使用图像捕捉意图,但系统将图像缩小到150 * 200,但感谢您现在我拥有全尺寸图像。 问题是图像的大小是一个大的(2-5mbs)我试图缩小位图方法和毕加索图书馆,但图像文件仍然具有相同的大小。你能给我指导如何减少它的大小(如果需要的话甚至是分辨率)。 我的尝试:减少位图大小
public void grabImage(ImageView imageView) {
this.getContentResolver().notifyChange(mImageUri, null);
ContentResolver cr = this.getContentResolver();
Bitmap bitmap;
try
{
bitmap = android.provider.MediaStore.Images.Media.getBitmap(cr, mImageUri);
//ByteArrayOutputStream bytes = new ByteArrayOutputStream();
Bitmap bm = ShrinkBitmap(fullpath, bitmap.getWidth(), bitmap.getHeight());
imageView.setImageBitmap(bm);
}
catch (Exception e)
{
Log.d("This", "Failed to load", e);
}
}
Bitmap ShrinkBitmap(String file, int width, int height){
BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
bmpFactoryOptions.inJustDecodeBounds = true;
Bitmap bitmap = BitmapFactory.decodeFile(file, bmpFactoryOptions);
int heightRatio = (int)Math.ceil(bmpFactoryOptions.outHeight/(float)height);
int widthRatio = (int)Math.ceil(bmpFactoryOptions.outWidth/(float)width);
if (heightRatio > 1 || widthRatio > 1)
{
if (heightRatio > widthRatio)
{
bmpFactoryOptions.inSampleSize = 4;
} else {
bmpFactoryOptions.inSampleSize = 4;
}
}
bmpFactoryOptions.inJustDecodeBounds = false;
bitmap = BitmapFactory.decodeFile(file, bmpFactoryOptions);
return bitmap;
}
问候,
显示你的尝试。 – iTurki
[如何在上载到服务器之前减少图像文件大小]的可能重复(http://stackoverflow.com/questions/18573774/how-to-reduce-an-image-file-size-before-uploading-to -a服务器) –