Skip to content Skip to sidebar Skip to footer

How To Set An Image Taken By The Camera In To An Imageview?

I am using camera 2 API for creating my own camera. I want to set the image taken by the camera in to an ImageView, which is on another activity. I have tried this code but it is n

Solution 1:

I think that you should pass the bitmap like this:

Intent intent = newIntent(this, ThirdActivity.class);
intent.putExtra("BitmapImage", photo);

and then receive it as parcelable data like this in your third activity:

Intentintent= getIntent();
Bitmapbitmap= (Bitmap) intent.getParcelableExtra("BitmapImage");

and then just set the bitmap to an ImageView

imageView.setImageBitmap(bitmap);

Hopefully this helps you :) Write if you have any exceptions

Solution 2:

add this line in class section

finalint TAKE_PHOTO_REQ = 100;


  ImageView imageView;

Add this two lines in your calling method

  imageView = (ImageView)findViewById(R.id.iv);
Intentintent=newIntent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, TAKE_PHOTO_REQ);

Add this

@OverridepublicvoidonActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
        case TAKE_PHOTO_REQU: {
            if (resultCode == TakePicture.RESULT_OK && data != null) {

                BitmapmyBmp= (Bitmap) data.getExtras().get("data");

                imageView.setImageBitmap(myBmp);
            }
        }
       }
      }

Hope this will helpful..thanks

Solution 3:

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

Post a Comment for "How To Set An Image Taken By The Camera In To An Imageview?"