我试图缩放图片,它起初运行良好,但是当缩小很多时它似乎不起作用。一段时间后,它停止缩小。我无法获得质量为0的小于630的字节数。我意识到这是一个垃圾图片,但我想要将其缩小很多,它根本不起作用。任何想法将不胜感激。Android位图不会缩放
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();
谢谢,但我需要缩小它,因为我需要通过网络发送它,并且我有严格的大小限制。我可以使用矩形来缩放它,然后从中获取一个字节数组吗? –