mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-02-12 01:10:42 +01:00
force image ratio 16:9
This commit is contained in:
parent
aaf87d49dc
commit
a9857c99f1
@ -36,7 +36,6 @@ public class PhotoProcessor extends AsyncTask<byte[], Void, Void> {
|
|||||||
final FileOutputStream fos = new FileOutputStream(photoFile);
|
final FileOutputStream fos = new FileOutputStream(photoFile);
|
||||||
/*Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
|
/*Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
|
||||||
bitmap = setBitmapRotation(bitmap, photoFile.toString());
|
bitmap = setBitmapRotation(bitmap, photoFile.toString());
|
||||||
bitmap = setAspectRatio(bitmap);
|
|
||||||
bitmap = checkLandscape(bitmap);
|
bitmap = checkLandscape(bitmap);
|
||||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);*/
|
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);*/
|
||||||
|
|
||||||
@ -97,17 +96,4 @@ public class PhotoProcessor extends AsyncTask<byte[], Void, Void> {
|
|||||||
|
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Bitmap setAspectRatio(Bitmap bitmap) {
|
|
||||||
final double wantedAspect = (double) 16 / (double) 9;
|
|
||||||
final double bmpWidth = bitmap.getWidth();
|
|
||||||
final double bmpHeight = bitmap.getHeight();
|
|
||||||
|
|
||||||
if (bmpHeight / bmpWidth < wantedAspect) {
|
|
||||||
final double extraWidth = bmpWidth - (bmpHeight / wantedAspect);
|
|
||||||
final int startX = (int) (extraWidth / 2);
|
|
||||||
return Bitmap.createBitmap(bitmap, startX, 0, (int) (bmpWidth - extraWidth), (int) bmpHeight);
|
|
||||||
}
|
|
||||||
return bitmap;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O
|
|||||||
private static final String TAG = Preview.class.getSimpleName();
|
private static final String TAG = Preview.class.getSimpleName();
|
||||||
private static final int FOCUS_AREA_SIZE = 200;
|
private static final int FOCUS_AREA_SIZE = 200;
|
||||||
private static final int PHOTO_PREVIEW_LENGTH = 1000;
|
private static final int PHOTO_PREVIEW_LENGTH = 1000;
|
||||||
|
private static final float RATIO_TOLERANCE = 0.1f;
|
||||||
|
|
||||||
private static SurfaceHolder surfaceHolder;
|
private static SurfaceHolder surfaceHolder;
|
||||||
private static Camera camera;
|
private static Camera camera;
|
||||||
@ -199,12 +200,13 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// limit the max picture size at 8 megapixels
|
|
||||||
private Camera.Size getPictureSize() {
|
private Camera.Size getPictureSize() {
|
||||||
List<Camera.Size> sizes = parameters.getSupportedPictureSizes();
|
List<Camera.Size> sizes = parameters.getSupportedPictureSizes();
|
||||||
Camera.Size maxSize = sizes.get(0);
|
Camera.Size maxSize = sizes.get(0);
|
||||||
for (Camera.Size size : sizes) {
|
for (Camera.Size size : sizes) {
|
||||||
if (size.width * size.height < 9000000) {
|
final boolean isEightMegapixelsMax = isEightMegapixelsMax(size);
|
||||||
|
final boolean isSixteenToNine = isSixteenToNine(size);
|
||||||
|
if (isEightMegapixelsMax && isSixteenToNine) {
|
||||||
maxSize = size;
|
maxSize = size;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -212,6 +214,17 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O
|
|||||||
return maxSize;
|
return maxSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isEightMegapixelsMax(Camera.Size size) {
|
||||||
|
return size.width * size.height < 9000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isSixteenToNine(Camera.Size size) {
|
||||||
|
final float currRatio = (float) size.height / size.width;
|
||||||
|
final float wantedRatio = (float) 9 / 16;
|
||||||
|
final float diff = Math.abs(currRatio - wantedRatio);
|
||||||
|
return diff < RATIO_TOLERANCE;
|
||||||
|
}
|
||||||
|
|
||||||
private void focusArea() {
|
private void focusArea() {
|
||||||
if (camera == null)
|
if (camera == null)
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user