Android 为什么缩放后的位图看起来是空的

Android 为什么缩放后的位图看起来是空的,android,Android,我正在尝试缩放位图,使其大小加倍 但缩放后位图显示为空,全部为纯灰色 代码如下: Matrix matrix = new Matrix(); // resize the bit map matrix.postScale(2, 2); // recreate the new Bitmap and set it back Bitmap bm2=Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(),

我正在尝试缩放位图,使其大小加倍

但缩放后位图显示为空,全部为纯灰色

代码如下:

Matrix matrix = new Matrix();

    // resize the bit map
    matrix.postScale(2, 2);

    // recreate the new Bitmap and set it back
    Bitmap bm2=Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true);   
    //bm.recycle();
编辑

我发现这是内存问题,如果我用小图像处理,效果会很好

大图片仍然存在问题

谢谢你的建议

从中可以清楚地看出,
Bitmap.createBitmap()
返回相同的位图或源位图的一部分。因此,它可能在这里返回相同的位图对象。但在这里,您正在回收它

bm.recycle();
这就是为什么你得到空值

使用这种方法

    public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
    int width = bm.getWidth();
    int height = bm.getHeight();
    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;
    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);

    Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height,
            matrix, false);
    return resizedBitmap;
}

传球宽度为1920,高度为2560

谢谢kalyan,如果我不循环,同样的结果-((是否有任何位图正在返回或为空?)它不是空的,在调试时正确显示双倍宽度和双倍高度,但全部为灰色…:-((发布源代码或两个版本的图像,包括缩放图像和普通图像)。