How to save images from Camera in Android to specific folder?

前端 未结 3 581
长情又很酷
长情又很酷 2020-12-03 11:13

Basically, what I want to do is allow the user to make their own folder and then go to an activity that contains a button to launch th

相关标签:
3条回答
  • 2020-12-03 11:50

    You should add the file location to the image capture intent. For example:

    camera.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, [file location]);
    

    Take a look here

    0 讨论(0)
  • 2020-12-03 11:53

    Try out this....

    path = Environment.getExternalStorageDirectory() + "/photo1.jpg";
    File file = new File(path);
    Uri outputFileUri = Uri.fromFile(file);
    Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
    startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY);
    

    and you haven't implemented onActivityResult() Try out this may help you.

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        System.gc();
        if (requestCode == CAPTURE_IMAGE_ACTIVITY) {
            if (resultCode == Activity.RESULT_OK) {
                try {
                    // Call function MakeFolder to create folder structure if
                    // its not created
                    if(imageBitmap != null) {
                        imageBitmap = null;
                        imageBitmap.recycle();
                    }
                    MakeFolder();
                    // Get file from temp1 file where image has been stored
                    BitmapFactory.Options options = new BitmapFactory.Options();
                    options.inSampleSize = 3;
                    imageBitmap = BitmapFactory.decodeFile(path, options);
                    imgForPhotograph.setImageBitmap(imageBitmap);
                    isImageTaken = true;
                    // Name for image
                    IMAGEPATH = getString(R.string.chassisImage)
                            + System.currentTimeMillis();
                    SaveImageFile(imageBitmap,IMAGEPATH);
                } catch (Exception e) {
                    Toast.makeText(this, "Picture Not taken",
                                    Toast.LENGTH_LONG).show();
                    e.printStackTrace();
                }
            }
        }
    
    0 讨论(0)
  • 2020-12-03 12:00

    add this code before calling camera activity,

    Uri uriSavedImage=Uri.fromFile(new File("/sdcard/flashCropped.png"));
    camera.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
    startActivityForResult(camera, 1);
    
    0 讨论(0)
提交回复
热议问题