-2

I coded when you click the button the camera opens and takes a new picture. I want that picture to turn into an ImageView on a new Activity. So I created the new activity and placed an ImageView on it:

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.amy.teacherfilesapp.Upload">

        <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/imageView"
        android:scaleType="centerCrop"
        />


</android.support.constraint.ConstraintLayout>

And then on the Main Activity I put(this whole thing applies to btn2so you can ignore btn1 & btn3, thanks):`package com.example.amy.teacherfilesapp;

import android.content.Intent;
import android.graphics.Bitmap;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;


public class MainActivity extends AppCompatActivity {

    Button btn1;
    Button btn2;
    Button btn3;
    ImageView imgTakenPic;
    private static final int CAM_REQUEST=1313;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        btn2 = (Button) findViewById(R.id.drawer_two);
        imgTakenPic = (ImageView)findViewById(R.id.imageView);
        btn2.setOnClickListener(new btnTakePhotoClicker());

        btn1 = (Button)findViewById(R.id.drawer_one);
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent openCabinet = new Intent(MainActivity.this,MyCabinet.class);
                startActivity(openCabinet);
            }
        });

        btn2 =(Button)findViewById(R.id.drawer_two);
        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent upload = new Intent("android.media.action.IMAGE_CAPTURE");
                startActivity(upload);
            }
        });

        btn3 = (Button)findViewById(R.id.drawer_three);
        btn3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent settings = new Intent(MainActivity.this, Settings.class);
                startActivity(settings);
            }
        });





    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if(requestCode == CAM_REQUEST){
            Bitmap bitmap = (Bitmap) data.getExtras().get("data");
            imgTakenPic.setImageBitmap(bitmap);
        }
    }

    class btnTakePhotoClicker implements  Button.OnClickListener{

        @Override
        public void onClick(View view) {
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(intent,CAM_REQUEST);
        }
    }
}

`

This didn't work as it didn't display the image anywhere I could see.

I would be very grateful if you could help me. Thanks.

  • where is your code to click photo and get it back. how have you transferred your image from that activity to here. – Kapil G Aug 08 '17 at 07:20
  • Take a look at an answer with sample code for this scenario: https://stackoverflow.com/a/5991757/232530 – Lukasz M Aug 08 '17 at 07:23
  • Please don't repeat questions. Simply editing your original post with any new information you have, any new code you've tried, or an explanation of why any posted answers aren't working will bump it to the top of the active queue. – Mike M. Aug 08 '17 at 07:28

1 Answers1

1

Use like this;

 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if(requestCode == CAM_REQUEST){
        Bitmap photo = (Bitmap) data.getExtras().get("data");
            /* Passing BITMAP to the Second Activity */
            Intent IntentCamera = new Intent(this, Second.class);
            IntentCamera.putExtra("BitmapImage", photo);
            startActivity(IntentCamera);
    }
}

in Second Activity;

 Intent intent_camera = getIntent();
Bitmap camera_img_bitmap = (Bitmap) intent_camera
        .getParcelableExtra("BitmapImage");
if (camera_img_bitmap != null) {
    img_to_be_zoomed.setImageBitmap(camera_img_bitmap);
}
Vishal Vaishnav
  • 3,346
  • 3
  • 26
  • 57