Skip to content

Commit cbb4e55

Browse files
committed
1. 解决少数机型拍照或对焦崩溃的问题 2. 解决用户裁剪的宽或高为0导致崩溃的问题
1 parent db1ad1e commit cbb4e55

4 files changed

Lines changed: 19 additions & 3 deletions

File tree

idcardcamera/src/main/java/com/wildma/idcardcamera/camera/CameraActivity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@ private void confirm() {
294294
mCropImageView.crop(new CropListener() {
295295
@Override
296296
public void onFinish(Bitmap bitmap) {
297+
if(bitmap == null) {
298+
Toast.makeText(getApplicationContext(), getString(R.string.crop_fail), Toast.LENGTH_SHORT).show();
299+
finish();
300+
}
297301

298302
/*保存图片到sdcard并返回图片路径*/
299303
if (FileUtils.createOrExistsDir(Constant.DIR_ROOT)) {

idcardcamera/src/main/java/com/wildma/idcardcamera/camera/CameraPreview.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,11 @@ private void release() {
166166
*/
167167
public void focus() {
168168
if (camera != null) {
169-
camera.autoFocus(null);
169+
try {
170+
camera.autoFocus(null);
171+
} catch (Exception e) {
172+
Log.d(TAG, "takePhoto " + e);
173+
}
170174
}
171175
}
172176

@@ -198,8 +202,11 @@ public boolean switchFlashLight() {
198202
*/
199203
public void takePhoto(Camera.PictureCallback pictureCallback) {
200204
if (camera != null) {
201-
camera.takePicture(null, null, pictureCallback);
202-
// camera.stopPreview();
205+
try {
206+
camera.takePicture(null, null, pictureCallback);
207+
} catch (Exception e) {
208+
Log.d(TAG, "takePhoto " + e);
209+
}
203210
}
204211
}
205212

idcardcamera/src/main/java/com/wildma/idcardcamera/cropper/CropOverlayView.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,10 @@ public void crop(CropListener cropListener, boolean needStretch) {
370370
Math.max(bitmapBottomRight.x, bitmapTopRight.x),
371371
Math.max(bitmapBottomRight.y, bitmapBottomLeft.y));
372372

373+
if(cropRect.width() <= 0 || cropRect.height() <= 0) { //用户裁剪的宽或高为0
374+
cropListener.onFinish(null);
375+
return;
376+
}
373377
Bitmap cut = Bitmap.createBitmap(
374378
output,
375379
cropRect.left,

idcardcamera/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
<string name="app_name">IDCardCamera</string>
33

44
<string name="touch_to_focus">触摸屏幕对焦</string>
5+
<string name="crop_fail">裁剪失败</string>
56
</resources>

0 commit comments

Comments
 (0)