【问题标题】:(android) how to overwrite image on DCIM folder?(android) 如何覆盖 DCIM 文件夹上的图像?
【发布时间】:2017-01-20 05:53:26
【问题描述】:

我已经有一个调整大小的位图对象。

有了这个位图,我怎样才能覆盖 DCIM 文件夹中的这个位图??

我知道我应该将位图更改为 File 对象...

请帮帮我

(假设我也有绝对路径)

我用下面的代码试过了。 仅当不存在具有相同名称的文件时,它才会创建一个新文件。 否则,它不会创建新文件。

private void SaveBitmapToFileCache(Bitmap bitmap, String strFilePath) {

    File fileCacheItem = new File(strFilePath);
    OutputStream out = null;

    try
    {
        fileCacheItem.createNewFile();
        out = new FileOutputStream(fileCacheItem);

        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
    finally
    {
        try
        {
            out.close();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }
}

【问题讨论】:

  • 运行一个条件,如果文件存在,删除它并继续创建一个新的!
  • 在下面查看我的答案。如果有帮助,请告诉我!

标签: android


【解决方案1】:

试试这样的:

//File file= new File("FilePath"+ "/myfolder/myimage.jpg");
    if(fileCacheItem .exists())
    {
         file.delete();
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-31
    • 2011-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多