Skip to content Skip to sidebar Skip to footer

How To Display Picture In Imageview Photo Taken By Camera In Android

can anybody tell How to display picture in imageview photo taken by using front camera in android can anybody provide code Thanks

Solution 1:

here is the code try it

here is my xml file

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"android:id="@+id/linear"><Buttonandroid:id="@+id/btn"android:layout_width="200dp"android:layout_height="wrap_content"android:text="Click" /><ImageViewandroid:id="@+id/img_preview"android:layout_width="fill_parent"android:layout_height="fill_parent" /></LinearLayout>

here is the activity code

Button btn;
intCAMERA_PIC_REQUEST=0;
ImageView imgView;

imgView = (ImageView) findViewById(R.id.img_preview);

    btn = (Button) findViewById(R.id.btn);
    btn.setCompoundDrawables(null, getResources().getDrawable(R.drawable.icon), null, null);
    btn.setOnClickListener(newOnClickListener() {
        @OverridepublicvoidonClick(View v) {
            Intentcamera_intent=newIntent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(camera_intent, CAMERA_PIC_REQUEST);
                    }
      });

here is the onActivityResult

@OverrideprotectedvoidonActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch(requestCode){
    case CAMERA_PIC_REQUEST:
        if(resultCode==RESULT_OK){
           Bitmapthumbnail= (Bitmap) data.getExtras().get("data");
           imgView.setImageBitmap(thumbnail);
            }
    }
}

Solution 2:

Solution 3:

Try this one

publicclassTakingImageextendsAppCompatActivity {

privatestaticfinalintCAMERA_REQUEST=1888;
private ImageView imageView;

publicvoidonCreate(Bundle savedInstance){
    super.onCreate(savedInstance);
    setContentView(R.layout.activity_choosing_photo);
    button = (Button)findViewById(R.id.button_select);
    imageView = (ImageView)findViewById(R.id.image_view);
    IntentcameraIntent=newIntent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
protectedvoidonActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
        Bitmapphoto= (Bitmap) data.getExtras().get("data");
        imageView.setImageBitmap(photo);
    }
}

activity_choosing_photo.xml

<ImageView
    android:id="@+id/image_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/flower"
    android:layout_marginLeft="100dp"/>
<Button
    android:id="@+id/button_select"
    android:layout_below="@+id/image_view"
    android:layout_marginTop="40dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Select"
    android:layout_marginLeft="140dp"/>

Post a Comment for "How To Display Picture In Imageview Photo Taken By Camera In Android"