1

我使用此代码重新扫描图库。但是每次我保存它都会覆盖画廊上的现有图像,唯一显示的图像是我保存的最新图像:(我该怎么办。请帮助:(

private boolean storeImage(Bitmap imageData, String filename) {

        String iconsStoragePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/" + "PixiePhotos" + "/";
        File sdIconStorageDir = new File(iconsStoragePath);
        sdIconStorageDir.mkdirs();


        try {
            String filePath = sdIconStorageDir.toString() + filename;
            FileOutputStream fileOutputStream = new FileOutputStream(filePath);

            BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream);
            imageData.compress(CompressFormat.JPEG, 100, bos);
            bos.flush();
            bos.close();
            //MediaScannerConnection.scanFile(this, new String[] { sdIconStorageDir.getPath() }, new String[] { "image/jpeg" }, null);
            File refreshFile = new File(filePath);
              Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
              scanIntent.setData(Uri.fromFile(refreshFile));
              sendBroadcast(scanIntent);




        } catch (FileNotFoundException e) {
            Log.w("TAG", "Error saving image file: " + e.getMessage());
            return false;
        } catch (IOException e) {
            Log.w("TAG", "Error saving image file: " + e.getMessage());
            return false;
        }

        return true;
    }
4

0 回答 0