安卓:获取文件名的相机? [英] Android : Getting file name from camera?

查看:145
本文介绍了安卓:获取文件名的相机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个小问题的东西,我可能只是远眺。

I have run into a small issue with something that I am probably just overlooking.

我想借此从相机表面preVIEW的图片,并将其保存到sd_card。这个工程几乎完美。我给它指定一个文件名,以及由于某种原因,它不使用的文件名。

I want to take a picture from the surface preview of the camera, and save it to the sd_card. This works ALMOST perfectly. I assign it a file name, and for one reason or another, it does not use the filename.

这是我一直在努力做的:

This is what I have been trying to do :

    Button imagecapture = (Button)findViewById(R.id.imagecapture);
	imagecapture.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
        	String filename = null;
        	ImageCaptureCallback iccb = null;

        		try {
        		filename = timeStampFormat.format(new Date());
        		ContentValues values = new ContentValues();
        		values.put(Media.TITLE, filename);
        		values.put(Media.DESCRIPTION, "Image capture by camera");

        		Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
        		iccb = new ImageCaptureCallback( getContentResolver().openOutputStream(uri));
        		} catch(Exception ex ){
        		ex.printStackTrace();
        		Log.e(getClass().getSimpleName(), ex.getMessage(), ex);
        		}
        	camera.takePicture(mShutterCallback, mPictureCallbackRaw, iccb);
        	com.froogloid.android.gspot.Park.imageFileName = filename;


        }
    });

这将不使用的文件名(如时间/日期戳我问它。)

It won't use the filename (i.e. time/date stamp I ask it to.)

推荐答案

这是由通过ImageCaptureCallback类实现PictureCallback,并覆盖该文件正在通过一个文件输出流写入onPictureTaken解决。所有你需要做的就是改变在FileOutput流到你想要的文件名。

This was resolved by implementing PictureCallback via a ImageCaptureCallback class, and Overriding the onPictureTaken where the file was being written via a file output stream. All you had to do was change the fileoutput stream to the filename you want.

这篇关于安卓:获取文件名的相机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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