04 - 11 14 : 44 : 30.845 19184 19255 E AndroidRuntime : java. lang. IllegalArgumentException: quality must be 0. .100
04 - 11 14 : 44 : 30.845 19184 19255 E AndroidRuntime : at android. graphics. Bitmap. compress ( Bitmap . java: 1436 )
public static Bitmap compressBitmap ( Bitmap bitmap, long limit) {
if ( bitmap != null ) {
int quality = 100 ;
ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream ( ) ;
bitmap. compress ( Bitmap. CompressFormat . JPEG, quality, byteOutStream) ;
while ( byteOutStream. toByteArray ( ) . length / 1024 > limit) {
byteOutStream. reset ( ) ;
quality -= 10 ;
if ( quality <= 0 ) {
quality += 10 ;
bitmap. compress ( Bitmap. CompressFormat . JPEG, quality, byteOutStream) ;
break ;
}
bitmap. compress ( Bitmap. CompressFormat . JPEG, quality, byteOutStream) ;
}
Log . d ( TAG, "quality is " + quality + " bitmap bytesize is " + bitmap. getByteCount ( ) ) ;
return BitmapFactory . decodeStream ( new ByteArrayInputStream ( byteOutStream. toByteArray ( ) ) , null , null ) ;
}
else {
return null ;
}
}