图片拾取,图片裁剪与图片设置流程测试完成。
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Thu Dec 04 08:21:41 GMT 2025
|
||||
#Thu Dec 04 08:31:49 GMT 2025
|
||||
stageCount=13
|
||||
libraryProject=
|
||||
baseVersion=15.11
|
||||
publishVersion=15.11.12
|
||||
buildCount=229
|
||||
buildCount=232
|
||||
baseBetaVersion=15.11.13
|
||||
|
||||
@@ -48,7 +48,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
|
||||
private AToolbar mAToolbar;
|
||||
private BackgroundView mBackgroundView;
|
||||
private File mfTakePhoto;
|
||||
boolean isCommitSettings = false;
|
||||
volatile boolean isCommitSettings = false;
|
||||
|
||||
@Override
|
||||
public Activity getActivity() {
|
||||
@@ -235,13 +235,13 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
|
||||
public void onClick(View v) {
|
||||
LogUtils.d(TAG, "【按钮点击】固定比例裁剪");
|
||||
// 调用裁剪工具类:传入上下文、预览图、固定比例(按视图宽高)、请求码
|
||||
startSystemCrop(
|
||||
mBgSourceUtils.getPreviewBackgroundBean(),
|
||||
mBackgroundView.getWidth(),
|
||||
mBackgroundView.getHeight(),
|
||||
false,
|
||||
REQUEST_CROP_IMAGE
|
||||
);
|
||||
ImageCropUtils.startImageCrop(BackgroundSettingsActivity.this,
|
||||
mBgSourceUtils.getPreviewBackgroundBean(),
|
||||
mBackgroundView.getWidth(),
|
||||
mBackgroundView.getHeight(),
|
||||
false,
|
||||
REQUEST_CROP_IMAGE
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -250,13 +250,13 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
|
||||
public void onClick(View v) {
|
||||
LogUtils.d(TAG, "【按钮点击】自由裁剪");
|
||||
// 调用裁剪工具类:传入上下文、预览图、自由裁剪(比例参数传0)、请求码
|
||||
startSystemCrop(
|
||||
mBgSourceUtils.getPreviewBackgroundBean(),
|
||||
0,
|
||||
0,
|
||||
true,
|
||||
REQUEST_CROP_IMAGE
|
||||
);
|
||||
ImageCropUtils.startImageCrop(BackgroundSettingsActivity.this,
|
||||
mBgSourceUtils.getPreviewBackgroundBean(),
|
||||
0,
|
||||
0,
|
||||
true,
|
||||
REQUEST_CROP_IMAGE
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -409,13 +409,13 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
|
||||
doubleRefreshPreview();
|
||||
|
||||
// 拍照后启动固定比例裁剪(调用工具类)
|
||||
startSystemCrop(
|
||||
mBgSourceUtils.getPreviewBackgroundBean(),
|
||||
mBackgroundView.getWidth(),
|
||||
mBackgroundView.getHeight(),
|
||||
false,
|
||||
REQUEST_CROP_IMAGE
|
||||
);
|
||||
ImageCropUtils.startImageCrop(BackgroundSettingsActivity.this,
|
||||
mBgSourceUtils.getPreviewBackgroundBean(),
|
||||
mBackgroundView.getWidth(),
|
||||
mBackgroundView.getHeight(),
|
||||
false,
|
||||
REQUEST_CROP_IMAGE
|
||||
);
|
||||
LogUtils.d(TAG, "【拍照完成】已启动裁剪");
|
||||
}
|
||||
|
||||
@@ -454,7 +454,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
|
||||
ToastUtils.show("拍照图片解析失败");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private void handleSelectPictureResult(int resultCode, Intent data) {
|
||||
if (resultCode != RESULT_OK || data == null) {
|
||||
handleOperationCancelOrFail();
|
||||
@@ -477,17 +477,17 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
|
||||
}
|
||||
|
||||
mBgSourceUtils.createCropFileProviderBackgroundBean(selectedImage);
|
||||
|
||||
|
||||
LogUtils.d(TAG, "【选图同步】路径绑定完成");
|
||||
// 选图后启动固定比例裁剪(调用工具类)
|
||||
mBgSourceUtils.loadSettings();
|
||||
startSystemCrop(
|
||||
mBgSourceUtils.getPreviewBackgroundBean(),
|
||||
mBackgroundView.getWidth(),
|
||||
mBackgroundView.getHeight(),
|
||||
false,
|
||||
REQUEST_CROP_IMAGE
|
||||
);
|
||||
ImageCropUtils.startImageCrop(BackgroundSettingsActivity.this,
|
||||
mBgSourceUtils.getPreviewBackgroundBean(),
|
||||
mBackgroundView.getWidth(),
|
||||
mBackgroundView.getHeight(),
|
||||
false,
|
||||
REQUEST_CROP_IMAGE
|
||||
);
|
||||
}
|
||||
|
||||
private void handleCropImageResult(int requestCode, int resultCode, Intent data) {
|
||||
@@ -719,7 +719,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
|
||||
* @param isFreeCrop 是否自由裁剪
|
||||
* @param requestCode 裁剪请求码
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取FileProvider Uri(复用方法,避免重复代码)
|
||||
@@ -767,72 +767,5 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void startSystemCrop(BackgroundBean cropBean, int aspectX, int aspectY, boolean isFreeCrop, int requestCode) {
|
||||
|
||||
LogUtils.d(TAG, "startSystemCrop: 启动系统裁剪,自由裁剪:" + isFreeCrop);
|
||||
File srcFile = new File(cropBean.getBackgroundFilePath());
|
||||
|
||||
// 校验原图
|
||||
if (srcFile == null || !srcFile.exists() || srcFile.length() <= 100) {
|
||||
Toast.makeText(this, "无有效图片可裁剪", Toast.LENGTH_SHORT).show();
|
||||
LogUtils.e(TAG, "startSystemCrop: 原图无效");
|
||||
return;
|
||||
}
|
||||
|
||||
// 生成输入Uri
|
||||
Uri inputUri = getFileProviderUri(srcFile);
|
||||
if (inputUri == null) {
|
||||
Toast.makeText(this, "获取图片Uri失败", Toast.LENGTH_SHORT).show();
|
||||
LogUtils.e(TAG, "startSystemCrop: 输入Uri生成失败");
|
||||
return;
|
||||
}
|
||||
|
||||
// 生成输出文件(使用BackgroundSourceUtils的压缩路径)
|
||||
BackgroundSourceUtils bgSourceUtils = BackgroundSourceUtils.getInstance(this);
|
||||
bgSourceUtils.loadSettings();
|
||||
File outputFile = new File(bgSourceUtils.getPreviewBackgroundBean().getBackgroundScaledCompressFilePath());
|
||||
if (outputFile == null) {
|
||||
Toast.makeText(this, "裁剪输出路径无效", Toast.LENGTH_SHORT).show();
|
||||
LogUtils.e(TAG, "startSystemCrop: 输出文件为空");
|
||||
return;
|
||||
}
|
||||
Uri outputUri = getFileProviderUri(outputFile);
|
||||
|
||||
|
||||
Uri cropOutPutUri = outputUri;
|
||||
|
||||
Intent intent = new Intent("com.android.camera.action.CROP");
|
||||
intent.setDataAndType(inputUri, "image/*");
|
||||
//intent.setDataAndType(inputUri, activity.getContentResolver().getType(inputUri));
|
||||
intent.putExtra("crop", "true");
|
||||
intent.putExtra("noFaceDetection", true);
|
||||
|
||||
if (!isFreeCrop) {
|
||||
intent.putExtra("aspectX", aspectX);
|
||||
intent.putExtra("aspectY", aspectY);
|
||||
}
|
||||
|
||||
// 修复:删除return-data=true,避免与EXTRA_OUTPUT冲突
|
||||
// intent.putExtra("return-data", true);
|
||||
// 修复1:明确禁用return-data,强制写入文件(关键)
|
||||
intent.putExtra("return-data", false);
|
||||
intent.putExtra(MediaStore.EXTRA_OUTPUT, cropOutPutUri);
|
||||
intent.putExtra("scale", true);
|
||||
// 修复2:启用缩放补全,确保图片适配输出尺寸(兼容性)
|
||||
intent.putExtra("scaleUpIfNeeded", true);
|
||||
intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
|
||||
// 修复3:授予读写权限,并添加FLAG_GRANT_PERSISTABLE_URI_PERMISSION(适配Android 11+写入权限)
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
|
||||
| Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||
| Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
|
||||
// 修复4:对输出目录授予临时写入权限(解决目录无写入权限问题)
|
||||
grantUriPermission("com.android.camera", outputUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
||||
|
||||
startActivityForResult(intent, requestCode);
|
||||
LogUtils.d(TAG, "startSystemCrop: 启动裁剪成功,输入路径:" + srcFile.getAbsolutePath() + ",输出路径:" + outputFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user