diff --git a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/CameraFragment.java b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/CameraFragment.java index ca0bb4a..3bdc1b5 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/CameraFragment.java +++ b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/CameraFragment.java @@ -127,7 +127,7 @@ public class CameraFragment extends Fragment implements PostUploader.PostUploadL public void onPictureTaken(byte[] data, Camera camera) { mPhoto = BitmapFactory.decodeByteArray(data, 0, data.length, null); - PicturePreview mPicPreview = new PicturePreview(getActivity().getBaseContext(), mPhoto); + PicturePreview mPicPreview = new PicturePreview(getActivity().getBaseContext(), mPhoto, facing); mPicPreview.setId(R.id.pic_preview); mCameraLayout.addView(mPicPreview); @@ -213,7 +213,7 @@ public class CameraFragment extends Fragment implements PostUploader.PostUploadL PicturePreview.filterPrev(); - PicturePreview mPicPreview = new PicturePreview(getActivity().getBaseContext(), mPhoto); + PicturePreview mPicPreview = new PicturePreview(getActivity().getBaseContext(), mPhoto, facing); mPicPreview.setId(R.id.pic_preview); mCameraLayout.addView(mPicPreview); @@ -231,7 +231,7 @@ public class CameraFragment extends Fragment implements PostUploader.PostUploadL PicturePreview.filterNext(); - PicturePreview mPicPreview = new PicturePreview(getActivity().getBaseContext(), mPhoto); + PicturePreview mPicPreview = new PicturePreview(getActivity().getBaseContext(), mPhoto, facing); mPicPreview.setId(R.id.pic_preview); mCameraLayout.addView(mPicPreview); diff --git a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/PicturePreview.java b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/PicturePreview.java index 47a2a46..33749e6 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/PicturePreview.java +++ b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/PicturePreview.java @@ -9,6 +9,7 @@ import android.graphics.ColorMatrix; import android.graphics.ColorMatrixColorFilter; import android.graphics.Matrix; import android.graphics.Paint; +import android.hardware.Camera; import android.util.Log; import android.view.SurfaceHolder; import android.view.SurfaceView; @@ -26,14 +27,24 @@ public class PicturePreview extends SurfaceView implements SurfaceHolder.Callbac private static int currentFilter = FILTER_NONE; + int facing; + int rotate; Bitmap picture; Bitmap filterPicture; - public PicturePreview(Context context, Bitmap bmp) { + public PicturePreview(Context context, Bitmap bmp, int facing) { super(context); setWillNotDraw(false); - picture = Bitmap.createScaledBitmap(bmp, bmp.getWidth() / 2, bmp.getHeight() / 2, false); + this.facing = facing; + + if (((Integer)facing).equals(Camera.CameraInfo.CAMERA_FACING_FRONT)) { + picture = Bitmap.createBitmap(bmp); + rotate = 270; + } else { + picture = Bitmap.createScaledBitmap(bmp, bmp.getWidth() / 2, bmp.getHeight() / 2, false); + rotate = 90; + } Log.d(TAG, "PicturePreview: " + bmp.getWidth() + " " + bmp.getHeight()); } @@ -47,8 +58,8 @@ public class PicturePreview extends SurfaceView implements SurfaceHolder.Callbac switch (currentFilter) { case FILTER_NONE: - canvas.drawBitmap(rotate(picture, 90), 0, 0, null); - filterPicture = rotate(picture, 90); + canvas.drawBitmap(rotate(picture, rotate), 0, 0, null); + filterPicture = rotate(picture, rotate); break; case FILTER_SEPIA: filterPicture = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888); @@ -62,8 +73,8 @@ public class PicturePreview extends SurfaceView implements SurfaceHolder.Callbac filter = new ColorMatrixColorFilter(cm); paint.setColorFilter(filter); - saveCanvas.drawBitmap(rotate(picture, 90), 0, 0, paint); - canvas.drawBitmap(rotate(picture, 90), 0, 0, paint); + saveCanvas.drawBitmap(rotate(picture, rotate), 0, 0, paint); + canvas.drawBitmap(rotate(picture, rotate), 0, 0, paint); break; case FILTER_BW: filterPicture = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888); @@ -73,8 +84,8 @@ public class PicturePreview extends SurfaceView implements SurfaceHolder.Callbac filter = new ColorMatrixColorFilter(cm); paint.setColorFilter(filter); saveCanvas.setBitmap(filterPicture); - saveCanvas.drawBitmap(rotate(picture, 90), 0, 0, paint); - canvas.drawBitmap(rotate(picture, 90), 0, 0, paint); + saveCanvas.drawBitmap(rotate(picture, rotate), 0, 0, paint); + canvas.drawBitmap(rotate(picture, rotate), 0, 0, paint); break; case FILTER_NEG: filterPicture = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888); @@ -88,8 +99,8 @@ public class PicturePreview extends SurfaceView implements SurfaceHolder.Callbac filter = new ColorMatrixColorFilter(cm); paint.setColorFilter(filter); saveCanvas.setBitmap(filterPicture); - saveCanvas.drawBitmap(rotate(picture, 90), 0, 0, paint); - canvas.drawBitmap(rotate(picture, 90), 0, 0, paint); + saveCanvas.drawBitmap(rotate(picture, rotate), 0, 0, paint); + canvas.drawBitmap(rotate(picture, rotate), 0, 0, paint); break; }