If you are using API level >= 14, you can easily use a TextureView to mirror the preview image back to the original. for SurfaceView you can apply Matrix to a captured Bitmap in onPictureTaken method. 


private Camera.PictureCallback mPicture = new Camera.PictureCallback() {

    @Override
    public void onPictureTaken(byte[] data, Camera camera) {

        Camera.CameraInfo info = new Camera.CameraInfo();
        Camera.getCameraInfo(cameraId, info);

        if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
            Bitmap newImage = null;
            Bitmap cameraBitmap = null;

            if (data != null) {
                cameraBitmap = BitmapFactory.decodeByteArray(data, 0, (data !=        null) ? data.length : 0);
            }
            Matrix matrix = new Matrix();
            matrix.preScale(1.0f, -1.0f);
            matrix.postRotate(270.f);

            newImage = Bitmap.createBitmap(cameraBitmap, 0, 0, cameraBitmap.getWidth(),
                    cameraBitmap.getHeight(), matrix, true);
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            newImage.compress(Bitmap.CompressFormat.JPEG, 100, stream);
            data = stream.toByteArray();
            if (newImage != null) {
                newImage.recycle();
                newImage = null;
            }

            if (cameraBitmap != null) {
                cameraBitmap.recycle();
                cameraBitmap = null;
            }

        }
    }
};

You may also like

Leave a Reply