简体   繁体   English

Android相机不保存图片

[英]android camera not saving picture

the following is my code to take a picture 以下是我的拍照代码

            File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
            String name = imageFileName;
            File file = new File(path, name);
            Toast.makeText(getBaseContext(), file.toString(), Toast.LENGTH_LONG).show();
            outputFileUri = Uri.fromFile(file);
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
            startActivityForResult(cameraIntent, CAMERA_REQUEST); 


}

static final int REQUEST_IMAGE_CAPTURE = 1;
protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    this.imageView = (ImageView)this.findViewById(R.id.mImageView);
    if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {  
        Bitmap photo = (Bitmap) data.getExtras().get("data"); 
        imageView.setImageBitmap(photo);
    }  

    }

This works fine takes the photo and puts a thumbnail in the imageview 这样可以很好地拍摄照片并将缩略图放在imageview中

problem is it saves the picture in the DCIM card on the SD Card when it should save it in the pictures folder with the filename "Imagefilename" 问题是它应将图片保存在文件名为“ Imagefilename”的图片文件夹中时,将图片保存在SD卡的DCIM卡中

the toast i have put in reports the full path as 我放入的吐司报告了完整的路径

storage/emulated/0/Pictures/filename.jpg but the picture is not saved there 存储/模拟/0/Pictures/filename.jpg,但图片未保存在此处

i have set read write permissions in the manifest 我在清单中设置了读写权限

any ideas where im going wrong 我在哪里出错的任何想法

Mark 标记

You need this: 你需要这个:

cameraIntent.putExtra( MediaStore.EXTRA_OUTPUT,outputFileUri );

prior to calling startActivityForResult.. so copying your code above: 在调用startActivityForResult ..之前,因此在上面复制代码:

        File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
        String name = imageFileName;
        File file = new File(path, name);
        Toast.makeText(getBaseContext(), file.toString(), Toast.LENGTH_LONG).show();
        outputFileUri = Uri.fromFile(file);
        Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 

        cameraIntent.putExtra( MediaStore.EXTRA_OUTPUT,outputFileUri );// add this

        startActivityForResult(cameraIntent, CAMERA_REQUEST); 

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

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