我尝试缩放图片,一开始效果很好,但是当缩小很多时,它似乎不起作用。一段时间后,它停止缩小。我无法在质量为 0 的情况下使字节数小于 630。我意识到这是一张糟糕的图片,但我想把它缩小很多,但它根本行不通。任何想法将不胜感激。
ByteArrayOutputStream out;
Bitmap bitmap = BitmapFactory.decodeStream(in);
int width = bitmap.getWidth(); //3920
int height = bitmap.getHeight(); //2204
float scale = 0.0034; //usually calculated in runtime but set for simplicity now.
// Resize the bitmap
Matrix matrix = new Matrix();
matrix.postScale(scale, scale);
// Recreate the new bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
out = new ByteArrayOutputStream();
resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 0, out);
return out.toByteArray();