Java 启动摄像机,但不要';无法保存图像
有没有办法使用相机,但只是暂时保存图像?我使用以下代码加载相机,然后使用onActivityResult()获取拍摄的图像(如果有…) 问题是,当拍摄图像时,它会保存到SD卡中 编辑 下面的代码调用了intentJava 启动摄像机,但不要';无法保存图像,java,android,android-intent,Java,Android,Android Intent,有没有办法使用相机,但只是暂时保存图像?我使用以下代码加载相机,然后使用onActivityResult()获取拍摄的图像(如果有…) 问题是,当拍摄图像时,它会保存到SD卡中 编辑 下面的代码调用了intent String imagePath; imagePath = Environment.getExternalStorageState() + "/images/myimage.jpg"; File file = new File( imagePath ); Uri outputFile
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
)
File imageFile = new File(imagePath);
imageFile.delete();
然而,图像永远不会被删除。另外,如果我进入我的gallery应用程序,图像是在有一个默认名称(如image57465.jpg)的情况下,我正在计算cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,outputFileUri)代码>实际上不起作用
编辑2
实际上,该文件正在保存到SD卡,并已正确删除。但是,似乎正在保存缩略图。您知道如何获取缩略图路径,以便在使用后将其删除吗?在捕获和保存时,将imagepath存储到变量,并在活动完成后从存储中删除文件(变量)
File mFile=new File(variable);
mfile.delete();
嗯,你不能在使用完图像后删除它吗?我只是快速查看了CameraAPI规范,没有找到任何东西表明可以将图像标记为临时图像
请尝试以下操作:
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();
}
}
}
让我知道它是否适合您。路径从哪里来?替换此imagePath=Environment.getExternalStorageState()+“/images/myimage.jpg”;使用imagePath=getExternalStorageDirectory()+“/images/myimage.jpg”;再试一次,朋友
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();
}
}
}