// Path: app/src/main/java/com/demo/amazing/util/BitmapUtil.java
// public class BitmapUtil {
// 
//     public static Bitmap rotateBitmap(Context context, Bitmap bitmap, int degree) {
//         Bitmap dest = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
// 
//         Canvas canvas = new Canvas(dest);
//         Matrix matrix = new Matrix();
//         matrix.setRotate(degree, bitmap.getWidth() / 2, bitmap.getWidth() / 2);
//         //matrix.setRotate(degree);
//         Paint paint = new Paint();
//         canvas.drawBitmap(bitmap, matrix, paint);
//         paint.setAntiAlias(true);
//         paint.setTextSize(28);
//         paint.setColor(context.getResources().getColor(R.color.colorAccent));
//         canvas.drawText("Image from", bitmap.getWidth() / 2, bitmap.getHeight() / 2, paint);
//         return dest;
//     }
// }
// 
// Path: app/src/main/java/com/demo/amazing/util/LogUtil.java
// public class LogUtil {
// 
//     public static void e(String msg) {
//         Log.e("free", msg);
//     }
// 
//     public static void d(String tag, String msg) {
//         Log.e("free", msg);
//     }
// }


import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.ImageFormat;
import android.graphics.Rect;
import android.graphics.YuvImage;
import android.hardware.Camera;
import android.media.ExifInterface;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.ImageView;
import com.demo.amazing.R;
import com.demo.amazing.util.BitmapUtil;
import com.demo.amazing.util.LogUtil;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
            Bitmap bitmap = BitmapFactory.decodeByteArray(stream.toByteArray(), 0, stream.size());

            stream.close();
            bitmap = BitmapUtil.rotateBitmap(this, bitmap, 270);
            imageView.setImageBitmap(bitmap);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onPictureTaken(byte[] data, Camera camera) {
        File file = new File(getImagePath());
        if (file == null) {
            return;
        }
        try {
            FileOutputStream outputStream = new FileOutputStream(file);
            outputStream.write(data);
            outputStream.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            ExifInterface exifInterface = new ExifInterface(file.getAbsolutePath());
            LogUtil.e("image orientation:" + exifInterface.getAttribute(ExifInterface.TAG_ORIENTATION));
            LogUtil.e("image width:" + exifInterface.getAttribute(ExifInterface.TAG_IMAGE_WIDTH));
// Path: app/src/main/java/com/demo/amazing/util/BitmapUtil.java
// public class BitmapUtil {
// 
//     public static Bitmap rotateBitmap(Context context, Bitmap bitmap, int degree) {
//         Bitmap dest = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
// 
//         Canvas canvas = new Canvas(dest);
//         Matrix matrix = new Matrix();
//         matrix.setRotate(degree, bitmap.getWidth() / 2, bitmap.getWidth() / 2);
//         //matrix.setRotate(degree);
//         Paint paint = new Paint();
//         canvas.drawBitmap(bitmap, matrix, paint);
//         paint.setAntiAlias(true);
//         paint.setTextSize(28);
//         paint.setColor(context.getResources().getColor(R.color.colorAccent));
//         canvas.drawText("Image from", bitmap.getWidth() / 2, bitmap.getHeight() / 2, paint);
//         return dest;
//     }
// }
// 
// Path: app/src/main/java/com/demo/amazing/util/LogUtil.java
// public class LogUtil {
// 
//     public static void e(String msg) {
//         Log.e("free", msg);
//     }
// 
//     public static void d(String tag, String msg) {
//         Log.e("free", msg);
//     }
// }


// Path: app/src/main/java/com/demo/amazing/activity/CameraActivity.java
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.ImageFormat;
import android.graphics.Rect;
import android.graphics.YuvImage;
import android.hardware.Camera;
import android.media.ExifInterface;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.ImageView;
import com.demo.amazing.R;
import com.demo.amazing.util.BitmapUtil;
import com.demo.amazing.util.LogUtil;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;

            Bitmap bitmap = BitmapFactory.decodeByteArray(stream.toByteArray(), 0, stream.size());

            stream.close();
            bitmap = BitmapUtil.rotateBitmap(this, bitmap, 270);
            imageView.setImageBitmap(bitmap);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onPictureTaken(byte[] data, Camera camera) {
        File file = new File(getImagePath());
        if (file == null) {
            return;
        }
        try {
            FileOutputStream outputStream = new FileOutputStream(file);
            outputStream.write(data);
            outputStream.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            ExifInterface exifInterface = new ExifInterface(file.getAbsolutePath());
            LogUtil.e("image orientation:" + exifInterface.getAttribute(ExifInterface.TAG_ORIENTATION));
            LogUtil.e("image width:" + exifInterface.getAttribute(ExifInterface.TAG_IMAGE_WIDTH));
            LogUtil.e("image height:" + exifInterface.getAttribute(ExifInterface.TAG_IMAGE_LENGTH));