1
在我的應用程序,當我從相機拍攝的照片,我需要得到該圖片的大小,並壓縮它,如果它超過指定的大小。 我應該如何知道圖像的大小,並根據我的申請將其壓縮 ..如何減少相機的圖片的大小android
請幫幫我。
在我的應用程序,當我從相機拍攝的照片,我需要得到該圖片的大小,並壓縮它,如果它超過指定的大小。 我應該如何知道圖像的大小,並根據我的申請將其壓縮 ..如何減少相機的圖片的大小android
請幫幫我。
爲了得到高度和寬度,你叫:
Uri imagePath = Uri.fromFile(tempFile);//Uri from camera intent
//Bitmap representation of camera result
Bitmap realImage = BitmapFactory.decodeFile(tempFile.getAbsolutePath());
realImage.getHeight();
realImage.getWidth();
調整圖像大小,我只是提供生成位圖到這種方法:
public static Bitmap scaleDown(Bitmap realImage, float maxImageSize,
boolean filter) {
float ratio = Math.min((float) maxImageSize/realImage.getWidth(),
(float) maxImageSize/realImage.getHeight());
int width = Math.round((float) ratio * realImage.getWidth());
int height = Math.round((float) ratio * realImage.getHeight());
Bitmap newBitmap = Bitmap.createScaledBitmap(realImage, width, height,
filter);
return newBitmap;
}
基本實際上只是Bitmap.createScaledBitmap()
。但是,我把它換成另一種方法來按比例縮小它。
感謝您的建議沉默,但我應該如何才能知道捕獲圖像的大小。以及此方法中使用布爾變量過濾器的id。 –
'filter'在這裏解釋:http://stackoverflow.com/questions/2895065/what-does-the-filter-parameter-to-createscaledbitmap-do – ariefbayu