Java 如何减少原始图像的大小?

Java 如何减少原始图像的大小?,java,android,bitmap,image-resizing,Java,Android,Bitmap,Image Resizing,我正在android上创建一个应用程序,它使用指纹阅读器,问题是图像是实时的,尺寸为800x750,字节数组大小为600000,当将其转换为位图并在imageview上分配时,该应用程序太令人鼓舞且崩溃。 如何减小原始图像字节数组的大小,以便我的应用程序可以毫无问题地提取指纹 imagePreview.setImageBitmap(imageData.toBitmap()); 我试过了,但还是很慢 Bitmap bmp = imageData.toBitmap();

我正在android上创建一个应用程序,它使用指纹阅读器,问题是图像是实时的,尺寸为800x750,字节数组大小为600000,当将其转换为位图并在imageview上分配时,该应用程序太令人鼓舞且崩溃。 如何减小原始图像字节数组的大小,以便我的应用程序可以毫无问题地提取指纹

imagePreview.setImageBitmap(imageData.toBitmap());
我试过了,但还是很慢

Bitmap bmp = imageData.toBitmap();
                        ByteArrayOutputStream stream = new ByteArrayOutputStream();
                        bmp.compress(Bitmap.CompressFormat.JPEG, 30, stream);
                        byte[] byteArray = stream.toByteArray();

                        BitmapFactory.Options options = new BitmapFactory.Options();
                        options.inPreferredConfig = Bitmap.Config.ARGB_8888;
                        options.inSampleSize = 2;
                        Bitmap bitmap = BitmapFactory.decodeByteArray(byteArray,0,byteArray.length,options);

你不能。如果您使用的是ARGB_8888,则图像将在内存中占用4*宽度*高度字节。没有办法减少这一点。如果你有问题,寻找内存泄漏,并考虑缓存。

如果希望位图比例相同并减小位图大小。然后通过你的极限 调整位图大小。

public Bitmap getResizedBitmap(Bitmap image, int maxSize) {
    int width = image.getWidth();
    int height = image.getHeight();

    float bitmapRatio = (float)width / (float) height;
    if (bitmapRatio > 1) {
        width = maxSize;
        height = (int) (width / bitmapRatio);
    } else {
        height = maxSize;
        width = (int) (height * bitmapRatio);
    }
    return Bitmap.createScaledBitmap(image, width, height, true);
 }