|
|
@ -50,12 +50,10 @@ public class CameraView extends FrameLayout implements LifecycleObserver { |
|
|
|
|
|
|
|
|
|
|
|
public final static int PERMISSION_REQUEST_CODE = 16; |
|
|
|
public final static int PERMISSION_REQUEST_CODE = 16; |
|
|
|
|
|
|
|
|
|
|
|
final static int DEFAULT_JPEG_QUALITY = 100; |
|
|
|
|
|
|
|
final static boolean DEFAULT_CROP_OUTPUT = false; |
|
|
|
final static boolean DEFAULT_CROP_OUTPUT = false; |
|
|
|
final static boolean DEFAULT_PLAY_SOUNDS = true; |
|
|
|
final static boolean DEFAULT_PLAY_SOUNDS = true; |
|
|
|
|
|
|
|
|
|
|
|
// Self managed parameters
|
|
|
|
// Self managed parameters
|
|
|
|
private int mJpegQuality; |
|
|
|
|
|
|
|
private boolean mCropOutput; |
|
|
|
private boolean mCropOutput; |
|
|
|
private boolean mPlaySounds; |
|
|
|
private boolean mPlaySounds; |
|
|
|
private HashMap<Gesture, GestureAction> mGestureMap = new HashMap<>(4); |
|
|
|
private HashMap<Gesture, GestureAction> mGestureMap = new HashMap<>(4); |
|
|
@ -100,7 +98,6 @@ public class CameraView extends FrameLayout implements LifecycleObserver { |
|
|
|
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CameraView, 0, 0); |
|
|
|
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CameraView, 0, 0); |
|
|
|
|
|
|
|
|
|
|
|
// Self managed
|
|
|
|
// Self managed
|
|
|
|
int jpegQuality = a.getInteger(R.styleable.CameraView_cameraJpegQuality, DEFAULT_JPEG_QUALITY); |
|
|
|
|
|
|
|
boolean cropOutput = a.getBoolean(R.styleable.CameraView_cameraCropOutput, DEFAULT_CROP_OUTPUT); |
|
|
|
boolean cropOutput = a.getBoolean(R.styleable.CameraView_cameraCropOutput, DEFAULT_CROP_OUTPUT); |
|
|
|
boolean playSounds = a.getBoolean(R.styleable.CameraView_cameraPlaySounds, DEFAULT_PLAY_SOUNDS); |
|
|
|
boolean playSounds = a.getBoolean(R.styleable.CameraView_cameraPlaySounds, DEFAULT_PLAY_SOUNDS); |
|
|
|
|
|
|
|
|
|
|
@ -175,7 +172,6 @@ public class CameraView extends FrameLayout implements LifecycleObserver { |
|
|
|
|
|
|
|
|
|
|
|
// Apply self managed
|
|
|
|
// Apply self managed
|
|
|
|
setCropOutput(cropOutput); |
|
|
|
setCropOutput(cropOutput); |
|
|
|
setJpegQuality(jpegQuality); |
|
|
|
|
|
|
|
setPlaySounds(playSounds); |
|
|
|
setPlaySounds(playSounds); |
|
|
|
|
|
|
|
|
|
|
|
// Apply camera controller params
|
|
|
|
// Apply camera controller params
|
|
|
@ -1074,27 +1070,6 @@ public class CameraView extends FrameLayout implements LifecycleObserver { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Sets the JPEG compression quality for image outputs. |
|
|
|
|
|
|
|
* @param jpegQuality a 0-100 integer. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public void setJpegQuality(int jpegQuality) { |
|
|
|
|
|
|
|
if (jpegQuality <= 0 || jpegQuality > 100) { |
|
|
|
|
|
|
|
throw new IllegalArgumentException("JPEG quality should be > 0 and <= 100"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
mJpegQuality = jpegQuality; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Gets the JPEG compression quality for image outputs. |
|
|
|
|
|
|
|
* @return a 0-100 integer |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public int getJpegQuality() { |
|
|
|
|
|
|
|
return mJpegQuality; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Whether we should crop the picture output to match CameraView aspect ratio. |
|
|
|
* Whether we should crop the picture output to match CameraView aspect ratio. |
|
|
|
* This is only relevant if CameraView dimensions were somehow constrained |
|
|
|
* This is only relevant if CameraView dimensions were somehow constrained |
|
|
@ -1587,7 +1562,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver { |
|
|
|
AspectRatio targetRatio = AspectRatio.of(w, h); |
|
|
|
AspectRatio targetRatio = AspectRatio.of(w, h); |
|
|
|
mLogger.i("processImage", "is consistent?", consistentWithView); |
|
|
|
mLogger.i("processImage", "is consistent?", consistentWithView); |
|
|
|
mLogger.i("processImage", "viewWidth?", getWidth(), "viewHeight?", getHeight()); |
|
|
|
mLogger.i("processImage", "viewWidth?", getWidth(), "viewHeight?", getHeight()); |
|
|
|
jpeg2 = CropHelper.cropToJpeg(jpeg, targetRatio, mJpegQuality); |
|
|
|
jpeg2 = CropHelper.cropToJpeg(jpeg, targetRatio, 100); |
|
|
|
} |
|
|
|
} |
|
|
|
dispatchOnPictureTaken(jpeg2); |
|
|
|
dispatchOnPictureTaken(jpeg2); |
|
|
|
} |
|
|
|
} |
|
|
@ -1607,10 +1582,10 @@ public class CameraView extends FrameLayout implements LifecycleObserver { |
|
|
|
AspectRatio targetRatio = AspectRatio.of(w, h); |
|
|
|
AspectRatio targetRatio = AspectRatio.of(w, h); |
|
|
|
mLogger.i("processSnapshot", "is consistent?", consistentWithView); |
|
|
|
mLogger.i("processSnapshot", "is consistent?", consistentWithView); |
|
|
|
mLogger.i("processSnapshot", "viewWidth?", getWidth(), "viewHeight?", getHeight()); |
|
|
|
mLogger.i("processSnapshot", "viewWidth?", getWidth(), "viewHeight?", getHeight()); |
|
|
|
jpeg = CropHelper.cropToJpeg(yuv, targetRatio, mJpegQuality); |
|
|
|
jpeg = CropHelper.cropToJpeg(yuv, targetRatio, 100); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
|
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
|
|
|
yuv.compressToJpeg(new Rect(0, 0, yuv.getWidth(), yuv.getHeight()), mJpegQuality, out); |
|
|
|
yuv.compressToJpeg(new Rect(0, 0, yuv.getWidth(), yuv.getHeight()), 100, out); |
|
|
|
jpeg = out.toByteArray(); |
|
|
|
jpeg = out.toByteArray(); |
|
|
|
} |
|
|
|
} |
|
|
|
dispatchOnPictureTaken(jpeg); |
|
|
|
dispatchOnPictureTaken(jpeg); |
|
|
|