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

强颜欢笑 提交于 2019-12-11 08:18:22

问题


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 ?


回答1:


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



回答2:


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




回答3:


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


来源:https://stackoverflow.com/questions/8891964/how-to-control-save-images-took-with-android-camera-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!