1
MediaStore를 사용하여 사진을 찍고 특정 폴더에 이미지를 저장하고 표시하려고합니다. 폴더가 생성되었지만 이미지 파일은 생성되지 않았습니다.안드로이드 카메라가 이미지를 저장하지 않습니다.
public void getPicture(View view)
{
File folder = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera/folder");
if(!folder.exists()) {
if(!folder.mkdirs()){
Toast.makeText(this, "cannot create folder", Toast.LENGTH_LONG).show();
}
}
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File imageFile = new File(folder, "image.jpg");
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
startActivityForResult(cameraIntent, RESULT_CAMERA);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
setContentView(R.layout.activity);
if(resultCode == Activity.RESULT_OK)
{
if(requestCode == RESULT_CAMERA)
{
Bitmap bitmap = BitmapFactory.decodeFile(REAR_END_PATH + "/image.jpg");
// create byte array from the Bitmap object
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 20, stream);
ImageView iv = new ImageView(this);
iv.setImageBitmap(bitmap);
setContentView(iv);
}
}
}