如何解决Xamarin Camera2 不保存第二张图片
我使用 xamarin camera2 api。 我的项目以相同的名称保存照片(覆盖一张图像)。 我为此设置了新文件名,但它会覆盖第一张图片。
public override void OnActivityCreated(Bundle savedInstanceState)
{
base.OnActivityCreated(savedInstanceState);
mFile = getOutputMediaFile();
mCaptureCallback = new CameraCaptureListener(this);
mOnImageAvailableListener = new ImageAvailableListener(this,mFile);
}
public void OnClick(View v)
{
//button Take photo code :
if (v.Id == Resource.Id.picture)
{
TakePicture();
mFile = getOutputMediaFile();
}
}
private File getOutputMediaFile()
{
File mediaStorageDir = new File(Activity.GetExternalFilesDir(null),"Pictures");
if (!mediaStorageDir.Exists())
{
if (!mediaStorageDir.Mkdirs())
{
Log.Debug("Pictures","failed to create Dir");
return null;
}
}
File mediaFile= new File(mediaStorageDir.Path,"pic.jpg");
int counter = 1;
while (mediaFile.Exists())
{
mediaFile = new File(mediaStorageDir.Path,"pic" + counter.ToString() + ".jpg");
counter++;
}
return mediaFile;
}
第一次:我拍了一张照片,它的工作并显示消息:保存的图像path/pic.jpg
第二次:当我拍照时,它显示消息:已保存图像 path/pic1.jpg ,但 pic1.jpg 未创建并且图片保存在 pic.jpg
我在 getOutputMediaFile()
mFile = pic1.jpg 中使用 Visual Studio 调试,但在 ImageAvailableListener
mFile = pic.jpg
public ImageAvailableListener(Camera2BasicFragment fragment,File file)
{
if (fragment == null)
throw new System.ArgumentNullException("fragment");
if (file == null)
throw new System.ArgumentNullException("file");
owner = fragment;
this.file = file;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。