|
|
@@ -185,17 +185,23 @@ public class OtaCameraActivity extends BaseCameraActivity {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ private boolean mIsRawOpen = false;
|
|
|
private File tempRawPhotoFile;
|
|
|
+ // 保存拍照的路径
|
|
|
+ private Uri mImageCaptureUri;
|
|
|
/**
|
|
|
* 打开原生相机
|
|
|
*/
|
|
|
private void openRawCamera() {
|
|
|
+ if (mIsRawOpen) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ mIsRawOpen = true;
|
|
|
tempRawPhotoFile = new File(Environment.getExternalStoragePublicDirectory(DIRECTORY_PICTURES) + "/" + System.currentTimeMillis() + ".jpg");
|
|
|
if (!tempRawPhotoFile.getParentFile().exists()) {
|
|
|
tempRawPhotoFile.getParentFile().mkdirs();
|
|
|
}
|
|
|
- // 保存拍照的路径
|
|
|
- Uri mImageCaptureUri;
|
|
|
+
|
|
|
// 跳转系统相机的intent
|
|
|
Intent takeIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
|
|
// 根据不同的Android版本uri不一样
|
|
|
@@ -205,6 +211,7 @@ public class OtaCameraActivity extends BaseCameraActivity {
|
|
|
} else {
|
|
|
mImageCaptureUri = Uri.fromFile(tempRawPhotoFile);
|
|
|
}
|
|
|
+
|
|
|
takeIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageCaptureUri);
|
|
|
|
|
|
camera.close();
|
|
|
@@ -219,9 +226,10 @@ public class OtaCameraActivity extends BaseCameraActivity {
|
|
|
@Override
|
|
|
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
+ mIsRawOpen = false;
|
|
|
if (resultCode == RESULT_OK) {
|
|
|
if (requestCode == 6) {
|
|
|
- correctPhotoRotation(tempRawPhotoFile);
|
|
|
+ correctPhotoRotation(tempRawPhotoFile, mImageCaptureUri);
|
|
|
// 通知相册去获取
|
|
|
//MediaScannerConnection.scanFile(this, new String[] { tempRawPhotoFile.getAbsolutePath() }, new String[] { "image/jpeg" }, null);
|
|
|
//cropPhoto(tempRawPhotoFile, getNewUri(tempRawPhotoFile));
|
|
|
@@ -241,8 +249,9 @@ public class OtaCameraActivity extends BaseCameraActivity {
|
|
|
return FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".provider", file);
|
|
|
}
|
|
|
|
|
|
- private void correctPhotoRotation(File imageFile) {
|
|
|
- Bitmap rawBitmap = ImageUtil.getBitmapFromUri(this, Uri.fromFile(imageFile));
|
|
|
+ private void correctPhotoRotation(File imageFile, Uri imageUri) {
|
|
|
+ //Bitmap rawBitmap = ImageUtil.getBitmapFromUri(this, Uri.fromFile(imageFile));
|
|
|
+ Bitmap rawBitmap = ImageUtil.getBitmapFromUri(this, mImageCaptureUri);
|
|
|
boolean correctSuccess = true;
|
|
|
try {
|
|
|
rawBitmap = ImageOrientation.modifyOrientation(imageFile.getAbsolutePath(), rawBitmap);
|
|
|
@@ -276,9 +285,9 @@ public class OtaCameraActivity extends BaseCameraActivity {
|
|
|
intent.putExtra("crop", "true");//可裁剪
|
|
|
//intent.putExtra("aspectX", 1); //裁剪的宽比例
|
|
|
//intent.putExtra("aspectY", 1); //裁剪的高比例
|
|
|
- intent.putExtra("outputX", mRight-mLeft); //裁剪的宽度
|
|
|
- intent.putExtra("outputY", mBottom-mTop); //裁剪的高度
|
|
|
- intent.putExtra("scale", false); //不限死比例
|
|
|
+ //intent.putExtra("outputX", mRight-mLeft); //裁剪的宽度
|
|
|
+ //intent.putExtra("outputY", mBottom-mTop); //裁剪的高度
|
|
|
+ intent.putExtra("scale", true); //可以改变裁剪大小
|
|
|
intent.putExtra(MediaStore.EXTRA_OUTPUT, croppedPhotoUri); //将裁剪的结果输出到指定的Uri
|
|
|
intent.putExtra("return-data", true); //若为true则表示返回数据
|
|
|
intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//裁剪成的图片的格式
|