Can't Display Captured Image to an other Activity, how to make it work?

227 Views Asked by At

I want to capture an image from custom camera and then display it on an other activity where i can add other png emoticons, i have this code but it doesnt show any photo after activity launches

1

There are 1 best solutions below

11
On

Please see some changes which i have done in your code.

1. please call new Intent after taking photo and the pass the filepath as i do.

MainActivity :

  ImageView mCaptureButton = (ImageView) findViewById(R.id.button_capture);
        mCaptureButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // get an image from the came
                        mCamPreview.captureImage(MainActivity.this);
    //starting(); // don't call Intent here
            }       
        });

    }

CameraPreview class:

private Activity _activity ;
    public void captureImage(Activity activity){
this._activity = activity;
    mCamera.takePicture(null, null, mJpegCallback);
}

PictureCallback mJpegCallback = new PictureCallback() {
    @Override
     public void onPictureTaken(byte[] data, Camera camera) {
        final Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);

        // Store bitmap to local storage
        FileOutputStream out = null;
        try {
            // Prepare file path to store bitmap
            // This will create Pictures/MY_APP_NAME_DIR/
            File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_PICTURES), "AVORI");
            if (!mediaStorageDir.exists()) {
                if (!mediaStorageDir.mkdirs()) {
                    Log.d(TAG, "failed to create directory");
                    return;
                }
            }

            // Bitmap will be stored at /Pictures/MY_APP_NAME_DIR/YOUR_FILE_NAME.jpg
            String filePath = mediaStorageDir.getPath() + File.separator + "Av.jpg";
            out = new FileOutputStream(filePath);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
//call EditPicture.class here
 Intent i = new Intent(_activity, EditPicture.class);
    i.putExtra("FILE_PATH", filePath );
startActivity(i); 
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (out != null) {
                    out.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
};