我有這臺機器,我必須捕獲產品的圖像並填充其他數據以將它們上載到服務器。我一直在使用圖像捕捉意圖,但系統將圖像縮小到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服務器) –