使用opencv的Android应用程序:如何在不覆盖的情况下保存图像? [英] Android App using opencv: how to save an image without overwriting?

查看:259
本文介绍了使用opencv的Android应用程序:如何在不覆盖的情况下保存图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我选择一个选项时,我正在使用以下代码将图像保存到文件夹:

I'm using the following code to save an image to a folder when I select an option:

File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
String filename = "teste.png";
File file = new File(path, filename);
filename = file.toString();
Highgui.imwrite(filename, mRgba);

但我希望保存的图像不会覆盖已存在于文件夹中的图像。我怎么能这样做?对于每个图像或类似的东西使用一种索引,我想,​​但是如何?

But i'd like the saved image to NOT OVERWRITE the image that's already in the folder. How could I do that? Using a kind of index for each image or something like that, I think, but how?

谢谢。

推荐答案

也许是这样的?

File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "MyAppDir");

if (!mediaStorageDir.exists()) {
    if (!mediaStorageDir.mkdirs()) {
        Log.e(TAG, "failed to create directory");
        return null;
    }
}

String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File mediaFile;
mediaFile = new File(mediaStorageDir.getPath() + File.separator + "testimage_" + timeStamp + ".png");

这篇关于使用opencv的Android应用程序:如何在不覆盖的情况下保存图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆