Android: Unable to cut out the overlay image and the photo within the overlay

227 views Asked by At

I have the following code where you can combine the photo data and the overlay image as one bitmap then save it. The problem is that I dont know how to cropout only the overlay image and the photo image within the overlay image. I dont want to save the preview image outside of the overlay image. It would be great if you can help me out with a sample or tips! I would love to hear from you!

I want to merge the data of the callback with the mOverlayLayout, its a RelativeLayout with a ImageView of a costume where you can place your face.

jpegCallback = (byte[] data, Camera camera) -> {
            Bitmap tmp_bitmap = BitmapFactory.decodeByteArray (data, 0, data.length);

            int width = tmp_bitmap.getWidth ();
            int height = tmp_bitmap.getHeight ();
            Matrix matrix = new Matrix ();
            int angleToRotate = CameraUtil.getRoatationAngle(CameraMainActivity.this,
                    Camera.CameraInfo.CAMERA_FACING_BACK);
            angleToRotate = angleToRotate + mPortrait;
            matrix.postRotate (angleToRotate);
            Bitmap bitmap = Bitmap.createBitmap (tmp_bitmap, 0, 0, width, height, matrix, true);
            Bitmap baseBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);

            mOverlayLayout.setDrawingCacheEnabled(true);
            mOverlayLayout.buildDrawingCache();
            Bitmap overlay = Bitmap.createBitmap(mOverlayLayout.getDrawingCache());
            mOverlayLayout.setDrawingCacheEnabled(false);


            Bitmap mergedImage = mCameraUtil.combineImages(overlay, baseBitmap);

// This is the method to combine the images

            public Bitmap combineImages(Bitmap frame, Bitmap image) {
        //Base frame source
        Rect src = new Rect(0,0, frame.getWidth(), frame.getHeight());
        RectF dst = new RectF(0, 0, image.getWidth(), image.getHeight());
        Paint paint = new Paint();
        Canvas comboImage = new Canvas(image);

        comboImage.drawBitmap(frame, src, dst, paint);
        Runtime.getRuntime().gc();
        return image;
}

//For example how will I crop out only the imageview overlay and the photo data within the overlay?

[sample image1

0

There are 0 answers