Merge branch 'felix' into 'master'

comments

See merge request !33
This commit was merged in pull request #33.
This commit is contained in:
Felix Atsma
2017-06-30 00:02:04 +02:00

View File

@@ -15,11 +15,10 @@ import android.view.SurfaceHolder;
import android.view.SurfaceView; import android.view.SurfaceView;
/** /**
* Created by felix on 23/06/2017. * Draws the picture taken and applies filters, which can be switched.
*/ */
public class PicturePreview extends SurfaceView implements SurfaceHolder.Callback { public class PicturePreview extends SurfaceView implements SurfaceHolder.Callback {
private static final String TAG = "PicturePreveiew"; private static final String TAG = "PicturePreview";
private static final int FILTER_NONE = 0; private static final int FILTER_NONE = 0;
private static final int FILTER_SEPIA = 1; private static final int FILTER_SEPIA = 1;
private static final int FILTER_BW = 2; private static final int FILTER_BW = 2;
@@ -27,11 +26,17 @@ public class PicturePreview extends SurfaceView implements SurfaceHolder.Callbac
private static int currentFilter = FILTER_NONE; private static int currentFilter = FILTER_NONE;
int facing; private int facing;
int rotate; private int rotate;
Bitmap picture; private Bitmap picture;
Bitmap filterPicture; private Bitmap filterPicture;
/**
* Constructor: changes image based on current direction the camera is facing.
* @param context
* @param bmp Image to be previewed.
* @param facing Direction camera is facing.
*/
public PicturePreview(Context context, Bitmap bmp, int facing) { public PicturePreview(Context context, Bitmap bmp, int facing) {
super(context); super(context);
setWillNotDraw(false); setWillNotDraw(false);
@@ -45,9 +50,12 @@ public class PicturePreview extends SurfaceView implements SurfaceHolder.Callbac
picture = Bitmap.createScaledBitmap(bmp, bmp.getWidth() / 2, bmp.getHeight() / 2, false); picture = Bitmap.createScaledBitmap(bmp, bmp.getWidth() / 2, bmp.getHeight() / 2, false);
rotate = 90; rotate = 90;
} }
Log.d(TAG, "PicturePreview: " + bmp.getWidth() + " " + bmp.getHeight());
} }
/**
* Checks the current filter and draws and saves the image with altered colours.
* @param canvas
*/
@Override @Override
protected void onDraw(Canvas canvas) { protected void onDraw(Canvas canvas) {
super.onDraw(canvas); super.onDraw(canvas);
@@ -107,6 +115,9 @@ public class PicturePreview extends SurfaceView implements SurfaceHolder.Callbac
} }
} }
/**
* Switches filter to the left.
*/
public static void filterPrev() { public static void filterPrev() {
switch (currentFilter) { switch (currentFilter) {
case FILTER_NONE: case FILTER_NONE:
@@ -124,6 +135,9 @@ public class PicturePreview extends SurfaceView implements SurfaceHolder.Callbac
} }
} }
/**
* Switches filter to the right.
*/
public static void filterNext() { public static void filterNext() {
switch (currentFilter) { switch (currentFilter) {
case FILTER_NONE: case FILTER_NONE:
@@ -141,6 +155,12 @@ public class PicturePreview extends SurfaceView implements SurfaceHolder.Callbac
} }
} }
/**
* Rotates an image by a specified amount of degrees by matrix.
* @param bmp Image to be rotated.
* @param degree Amount of degrees to rotate
* @return Rotated image.
*/
public static Bitmap rotate(Bitmap bmp, int degree) { public static Bitmap rotate(Bitmap bmp, int degree) {
Matrix mtx = new Matrix(); Matrix mtx = new Matrix();
mtx.postRotate(degree); mtx.postRotate(degree);
@@ -161,9 +181,12 @@ public class PicturePreview extends SurfaceView implements SurfaceHolder.Callbac
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
} }
/**
* Recycles pictures to free memory.
* @param holder
*/
@Override @Override
public void surfaceDestroyed(SurfaceHolder holder) { public void surfaceDestroyed(SurfaceHolder holder) {
Log.d(TAG, "surfaceDestroyed: PICTURE DESTROYED");
picture.recycle(); picture.recycle();
filterPicture.recycle(); filterPicture.recycle();
} }