启动摄像头的意图,但不保存图像 [英] Start a camera intent, but don't save image

查看:341
本文介绍了启动摄像头的意图,但不保存图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用摄像头,但只是暂时保存图像?我用下面的code加载了相机,然后我用onActivityResult(),以获得所拍摄的影像(如有的话...)

Is there a way to use the camera, but only temporarily save the image? I'm using the following code to load up the camera, then I'm using onActivityResult() to get the image taken (if any...)

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

的问题是,当图像被拍摄,它被保存到SD卡

the problem is that when the image gets taken, it is saved to the SD card.

修改

这样做的目的是呼吁通过以下code

The intent is called by the following code

String imagePath;

imagePath = Environment.getExternalStorageState() + "/images/myimage.jpg";
File file = new File( imagePath );
Uri outputFileUri = Uri.fromFile( file );

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri );
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);

在活动返回数据( onActivityResult )我使用的是

When the activity returns data (onActivityResult) I'm using

File imageFile = new File(imagePath);
imageFile.delete();

Howver的形象永远不会被删除。另外,如果我一头扎进我的画廊应用程序,图像中有一个默认的名称(如image57465.jpg),我asuming的 cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,outputFileUri); 是不实际的工作。

编辑2

事实上,该文件被保存到的SD卡,并正确删除。然而,似乎缩略图被保存。哎知道怎么去缩略图路径,这样我就可以删除它,我已经用它之后?

Actually, the file is being saved to the SDCARD, and deleted correctly. However, it seems that the thumbnail is being saved. Ay idea how to get the thumbnail path so i can delete it after i've used it?

推荐答案

好了,你就不能删除图像,当你用它做?我只是快速检查了摄像机API规格,而我不能完全找到任何指示,你可以标记的图像作为暂时的。

Well, can't you just delete the image when you're done using it? I just quick-checked the Camera API-specification, and I couldn't quite find anything that indicates that you can flag an image as temporary.

请尝试以下操作:

public onActivityResult(int request, int result, Intent data) {

    if( request == CAPTURE_IMAGE ) {

        if( result == RESULT_OK ) {

            /*Use the image in the way you want to here and save the path */

            //Delete the image
            File image = new File(path);
            image.delete();

        }

    }

}

让我知道,如果它的工作原理为你。

Let me know if it works out for you.

这篇关于启动摄像头的意图,但不保存图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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