Android缩放图像副本,而不是更改源图像

Android缩放图像副本,而不是更改源图像,android,image,bitmap,Android,Image,Bitmap,我有以下代码来获取小尺寸的头像图像: Bitmap b= BitmapFactory.decodeFile(selectedImagePath); File file = new File(selectedImagePath); Bitmap out = Bitmap.createScaledBitmap(b, 128, 128, false); FileOutputStream fOut; try { fOut = new FileOut

我有以下代码来获取小尺寸的头像图像:

    Bitmap b= BitmapFactory.decodeFile(selectedImagePath);
    File file = new File(selectedImagePath);
    Bitmap out = Bitmap.createScaledBitmap(b, 128, 128, false);
    FileOutputStream fOut;
    try {
        fOut = new FileOutputStream(file);
        out.compress(Bitmap.CompressFormat.PNG, 100, fOut);
        fOut.flush();
        fOut.close();
        b.recycle();
        out.recycle();
    } 
问题是,在执行此代码后,我在gallery中的图像也会被重新缩放,但我必须保持它不变。 我尝试使用位图图像的副本,如下所示:

Bitmap bmp2 = b.copy(b.getConfig(), true);
Bitmap out = Bitmap.createScaledBitmap(bpm2, 128, 128, false);


但我原来的形象仍然在改变。我如何获得此图像的新的独立副本

您正在从selectedImagePath加载图像,然后您的输出文件指向同一路径,当您调用compress时,您将覆盖原始图像

尝试为已调整大小的图像创建新名称

fOut = new FileOutputStream(renamedFile);

非常感谢。这就是问题所在。
fOut = new FileOutputStream(renamedFile);