简体   繁体   English

启动相机意图,但不保存图像

[英]Start a camera intent, but don't save image

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...)我正在使用以下代码加载相机,然后我使用 onActivityResult() 来获取图像(如果有的话......)

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

the problem is that when the image gets taken, it is saved to the SD card.问题是当图像被拍摄时,它被保存到 SD 卡中。

EDIT编辑

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);

When the activity returns data ( onActivityResult ) I'm using当活动返回数据( onActivityResult )我正在使用

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

Howver the image never gets deleted.但是图像永远不会被删除。 Also, if i head into my gallery application, the image is in there was a default name (like image57465.jpg), I'm asuming the cameraIntent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri );另外,如果我进入我的画廊应用程序,图像中有一个默认名称(如 image57465.jpg),我假设cameraIntent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri ); is not actually working.实际上没有工作。

EDIT 2编辑 2

Actually, the file is being saved to the SDCARD, and deleted correctly.实际上,该文件正在保存到 SDCARD 中,并被正确删除。 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?知道如何获取缩略图路径,以便在使用后将其删除吗?

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.我只是快速检查了相机 API 规范,但我找不到任何表明您可以将图像标记为临时图像的内容。

Try the following:尝试以下操作:

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.让我知道它是否适合你。

At the time of capture & saving, store imagepath to the variable and once your activity is done then remove the file(variable) from the storage在捕获和保存时,将图像路径存储到变量中,一旦您的活动完成,然后从存储中删除文件(变量)

File mFile=new File(variable);
mfile.delete();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM