在android上旋转位图而不出现OutOfMemory异常

在android上旋转位图而不出现OutOfMemory异常,android,bitmap,image-rotation,Android,Bitmap,Image Rotation,这是我旋转图像的代码。图像已经下采样和解码。但这会引发异常,因为它会创建图像的附加副本。如何安全地生成图像 public Bitmap rotateBitmap(Bitmap image, int angle) { if (image != null) { Matrix matrix = new Matrix(); matrix.postRotate(angle, (image.getWidth()) / 2,

这是我旋转图像的代码。图像已经下采样和解码。但这会引发异常,因为它会创建图像的附加副本。如何安全地生成图像

 public Bitmap rotateBitmap(Bitmap image, int angle) {
        if (image != null) {

            Matrix matrix = new Matrix();
            matrix.postRotate(angle, (image.getWidth()) / 2,
                    (image.getHeight()) / 2);

            return Bitmap.createBitmap(image, 0, 0, image.getWidth(),
                    image.getHeight(), matrix, true);
        }
        return null;
    }

选中此项,并在不需要位图时调用位图#回收。问题在于位图大小。确保重用位图变量或使用bitmap.recycle();严格来说,这不是一个答案,但Android在处理位图时是一个雷区。如果使用一个经过测试的库,例如.Thank。我可以在创建新图像后将输入图像循环到该方法。但是,我不认为这会解决问题,因为在轮换的过程中,回忆录的问题会出现。有没有其他方法可以做到这一点,而无需在内存中复制图像