how to control/save images took with android camera programmatically?

3.4k Views Asked by At

i've been trying to create a camera-related app. i know that i could create it programmatically from top, but i would prefer using the one that the phone supports.

what i mean is, rather then creating the camera from 0, i would/could call the camera activity. after all, it provides all the system and gui that i needed.

however, the problem is i wanted the result/image took to be saved in a folder that i created before, rather then saving it in the default camera folder. and also renaming the image took that instant from the default 'image' to names that i preferred.

how do i control that ?

3

There are 3 best solutions below

0
anju_john On BEST ANSWER

Try this. Here am saving picture to sdcard and also changing its name while saving.

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

Uri mUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),
                "pic"+ String.valueOf(System.currentTimeMillis()) + ".jpg"));

intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mUri);
0
JoxTraex On

If you look at the Camera applicaton source code, it allows for startActivityForResult(..) that can return the image back to you. This is ideally what you'd like to do.

As a Little hint:

MediaStore

2
AAnkit On

Use below method to take picture, SD_CARD_TEMP_DIR is the path and the image name you want it to store. Hope it help

     private void   takePicture(){

    SD_CARD_TEMP_DIR = Environment.getExternalStorageDirectory() + File.separator + "farmerImage"+CassavaPref.getInstance(this).getImageSuffix()+".jpg";
    file =new File(SD_CARD_TEMP_DIR);
    Intent takePictureFromCameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    takePictureFromCameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
    startActivityForResult(takePictureFromCameraIntent, 1111);
}