«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

올해는 머신러닝이다.

camera intent 관련 flag 팁 본문

Android/Tip&Tech

camera intent 관련 flag 팁

행복한 수지아빠 2011. 6. 21. 15:03
private Uri imageUri;

public void takePhoto(View view) {
   
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
   
File photo = new File(Environment.getExternalStorageDirectory(),  "Pic.jpg");
    intent
.putExtra(MediaStore.EXTRA_OUTPUT,
           
Uri.fromFile(photo));
    imageUri
= Uri.fromFile(photo);
    startActivityForResult
(intent, TAKE_PICTURE);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
   
super.onActivityResult(requestCode, resultCode, data);
   
switch (requestCode) {
   
case TAKE_PICTURE:
       
if (resultCode == Activity.RESULT_OK) {
           
Uri selectedImage = imageUri;
            getContentResolver
().notifyChange(selectedImage, null);
           
ImageView imageView = (ImageView) findViewById(R.id.ImageView);
           
ContentResolver cr = getContentResolver();
           
Bitmap bitmap;
           
try {
                 bitmap
= android.provider.MediaStore.Images.Media
                 
.getBitmap(cr, selectedImage);

                imageView
.setImageBitmap(bitmap);
               
Toast.makeText(this, selectedImage.toString(),
                       
Toast.LENGTH_LONG).show();
           
} catch (Exception e) {
               
Toast.makeText(this, "Failed to load", Toast.LENGTH_SHORT)
                       
.show();
               
Log.e("Camera", e.toString());
           
}
       
}
   
}
}