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

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

问题描述

我遇到了一个我可能只是俯视的小问题。

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

我想从相机的表面预览拍摄一张照片,并保存它到sd_card。这工作完美的ALMOST。我为它分配一个文件名,并且由于某种原因,它不使用文件名。

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;


        }
    }); 

它不会使用文件名(例如我要求的时间/日期戳) p>

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.

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

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