20251201_023218_404
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Sun Nov 30 18:04:35 GMT 2025
|
#Sun Nov 30 18:31:19 GMT 2025
|
||||||
stageCount=13
|
stageCount=13
|
||||||
libraryProject=
|
libraryProject=
|
||||||
baseVersion=15.11
|
baseVersion=15.11
|
||||||
publishVersion=15.11.12
|
publishVersion=15.11.12
|
||||||
buildCount=13
|
buildCount=15
|
||||||
baseBetaVersion=15.11.13
|
baseBetaVersion=15.11.13
|
||||||
|
|||||||
@@ -528,7 +528,6 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存剪裁后的Bitmap(彻底修复:路径拼接+权限+解析异常)
|
* 保存剪裁后的Bitmap(彻底修复:路径拼接+权限+解析异常)
|
||||||
*/
|
*/
|
||||||
@@ -557,10 +556,10 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 核心修复1:正确获取保存路径(直接使用完整路径,避免重复拼接)
|
// 核心修复1:统一保存路径到_mSourceCroppedFile(最终目标文件)
|
||||||
|
File fScaledCompressBitmapFile = _mSourceCroppedFile;
|
||||||
|
String scaledCompressFilePath = fScaledCompressBitmapFile.getAbsolutePath();
|
||||||
BackgroundSourceUtils utils = BackgroundSourceUtils.getInstance(this);
|
BackgroundSourceUtils utils = BackgroundSourceUtils.getInstance(this);
|
||||||
String scaledCompressFilePath = utils.getPreviewBackgroundScaledCompressFilePath(); // 完整路径(无嵌套)
|
|
||||||
File fScaledCompressBitmapFile = new File(scaledCompressFilePath);
|
|
||||||
|
|
||||||
// 确保保存目录存在(避免路径无效)
|
// 确保保存目录存在(避免路径无效)
|
||||||
File parentDir = fScaledCompressBitmapFile.getParentFile();
|
File parentDir = fScaledCompressBitmapFile.getParentFile();
|
||||||
@@ -588,20 +587,23 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
|
|||||||
// 修复2:设置文件可写权限(避免写入失败)
|
// 修复2:设置文件可写权限(避免写入失败)
|
||||||
fScaledCompressBitmapFile.setWritable(true, false);
|
fScaledCompressBitmapFile.setWritable(true, false);
|
||||||
fos = new FileOutputStream(fScaledCompressBitmapFile);
|
fos = new FileOutputStream(fScaledCompressBitmapFile);
|
||||||
|
// 核心修复3:根据目标文件名自动适配压缩格式(兼容JPEG/PNG)
|
||||||
|
Bitmap.CompressFormat compressFormat = _mSourceCroppedFileName.endsWith(".png")
|
||||||
|
? Bitmap.CompressFormat.PNG
|
||||||
|
: Bitmap.CompressFormat.JPEG;
|
||||||
// 压缩保存(80%质量,平衡清晰度和大小)
|
// 压缩保存(80%质量,平衡清晰度和大小)
|
||||||
boolean success = scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 80, fos);
|
boolean success = scaledBitmap.compress(compressFormat, 80, fos);
|
||||||
fos.flush();
|
fos.flush();
|
||||||
if (success) {
|
if (success) {
|
||||||
ToastUtils.show("图片压缩保存成功");
|
ToastUtils.show("图片压缩保存成功");
|
||||||
BackgroundBean previewBean = utils.getPreviewBackgroundBean();
|
BackgroundBean previewBean = utils.getPreviewBackgroundBean();
|
||||||
// 修复3:同步裁剪后文件名到预览Bean(仅传文件名,避免路径污染)
|
// 修复4:同步目标文件名到预览Bean(确保后续读取正确)
|
||||||
String cropFileName = fScaledCompressBitmapFile.getName();
|
previewBean.setBackgroundFileName(_mSourceCroppedFileName);
|
||||||
previewBean.setBackgroundFileName(cropFileName);
|
|
||||||
previewBean.setIsUseBackgroundFile(true); // 强制启用背景图
|
previewBean.setIsUseBackgroundFile(true); // 强制启用背景图
|
||||||
previewBean.setIsUseScaledCompress(true);
|
previewBean.setIsUseScaledCompress(true);
|
||||||
utils.saveSettings(); // 持久化配置
|
utils.saveSettings(); // 持久化配置
|
||||||
|
|
||||||
// 清理临时文件(双重保障)
|
// 核心修复5:保存成功后再清理临时文件(避免提前删除导致读取失败)
|
||||||
if (_mSourceCropTempFile.exists()) {
|
if (_mSourceCropTempFile.exists()) {
|
||||||
_mSourceCropTempFile.delete();
|
_mSourceCropTempFile.delete();
|
||||||
LogUtils.d(TAG, "裁剪成功,清理临时文件:" + _mSourceCropTempFile.getPath());
|
LogUtils.d(TAG, "裁剪成功,清理临时文件:" + _mSourceCropTempFile.getPath());
|
||||||
@@ -624,7 +626,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
|
|||||||
bvPreviewBackground.reloadPreviewBackground();
|
bvPreviewBackground.reloadPreviewBackground();
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
LogUtils.e(TAG, "文件未找到:" + e.getMessage() + ",保存路径:" + fScaledCompressBitmapFile.getPath());
|
LogUtils.e(TAG, "文件未找到:" + e.getMessage() + ",保存路径:" + scaledCompressFilePath);
|
||||||
ToastUtils.show("保存失败:文件路径无效");
|
ToastUtils.show("保存失败:文件路径无效");
|
||||||
// 异常时清理临时文件
|
// 异常时清理临时文件
|
||||||
if (_mSourceCropTempFile.exists()) {
|
if (_mSourceCropTempFile.exists()) {
|
||||||
@@ -695,6 +697,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
|
|||||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
@@ -792,10 +795,27 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
|
|||||||
if (_mSourceCropTempFile.exists() && _mSourceCropTempFile.length() > 0) {
|
if (_mSourceCropTempFile.exists() && _mSourceCropTempFile.length() > 0) {
|
||||||
LogUtils.d(TAG, String.format("_mSourceCropTempFile 信息:路径=%s , 大小=%d bytes",
|
LogUtils.d(TAG, String.format("_mSourceCropTempFile 信息:路径=%s , 大小=%d bytes",
|
||||||
_mSourceCropTempFile.getPath(), _mSourceCropTempFile.length()));
|
_mSourceCropTempFile.getPath(), _mSourceCropTempFile.length()));
|
||||||
// 优化Bitmap解析选项(避免OOM和损坏图片解析失败)
|
// 核心修复:优化Bitmap解析选项(自动适配格式+防止OOM+避免损坏图片解析失败)
|
||||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||||
options.inPreferredConfig = Bitmap.Config.RGB_565; // 省内存(仅RGB,无透明通道)
|
// 第一步:仅获取图片信息,不加载Bitmap(避免OOM)
|
||||||
options.inSampleSize = 1; // 不缩放(保证清晰度)
|
options.inJustDecodeBounds = true;
|
||||||
|
BitmapFactory.decodeFile(_mSourceCropTempFile.getPath(), options);
|
||||||
|
|
||||||
|
// 自动适配图片格式(PNG用ARGB_8888,JPEG用RGB_565省内存)
|
||||||
|
String imageMimeType = options.outMimeType;
|
||||||
|
options.inPreferredConfig = (imageMimeType != null && imageMimeType.contains("png"))
|
||||||
|
? Bitmap.Config.ARGB_8888
|
||||||
|
: Bitmap.Config.RGB_565;
|
||||||
|
|
||||||
|
// 自动计算采样率(防止大图片OOM,最大边长限制为2048)
|
||||||
|
int maxImageSize = 2048;
|
||||||
|
int sampleRate = 1;
|
||||||
|
while (options.outWidth / sampleRate > maxImageSize || options.outHeight / sampleRate > maxImageSize) {
|
||||||
|
sampleRate *= 2;
|
||||||
|
}
|
||||||
|
options.inSampleSize = sampleRate;
|
||||||
|
|
||||||
|
// 第二步:正式加载Bitmap
|
||||||
options.inJustDecodeBounds = false;
|
options.inJustDecodeBounds = false;
|
||||||
cropBitmap = BitmapFactory.decodeFile(_mSourceCropTempFile.getPath(), options);
|
cropBitmap = BitmapFactory.decodeFile(_mSourceCropTempFile.getPath(), options);
|
||||||
} else {
|
} else {
|
||||||
@@ -805,7 +825,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
|
|||||||
|
|
||||||
// 检查解析后的Bitmap是否有效
|
// 检查解析后的Bitmap是否有效
|
||||||
if (cropBitmap != null && !cropBitmap.isRecycled()) {
|
if (cropBitmap != null && !cropBitmap.isRecycled()) {
|
||||||
saveCropBitmap(cropBitmap); // 调用保存方法(内含修复逻辑)
|
saveCropBitmap(cropBitmap); // 调用修复后的保存方法
|
||||||
} else {
|
} else {
|
||||||
ToastUtils.show("获取剪裁图片失败(Bitmap解析异常)");
|
ToastUtils.show("获取剪裁图片失败(Bitmap解析异常)");
|
||||||
// 清理无效临时文件
|
// 清理无效临时文件
|
||||||
@@ -829,11 +849,8 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
|
|||||||
_mSourceCropTempFile.delete();
|
_mSourceCropTempFile.delete();
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
// 裁剪流程结束,强制清理临时文件(双重保障,避免残留)
|
// 核心修复:移除临时文件清理代码(已移至saveCropBitmap成功后清理)
|
||||||
if (_mSourceCropTempFile.exists()) {
|
LogUtils.d(TAG, "裁剪流程结束");
|
||||||
_mSourceCropTempFile.delete();
|
|
||||||
LogUtils.d(TAG, "裁剪流程结束,强制清理临时文件:" + _mSourceCropTempFile.getPath());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (resultCode != RESULT_OK) {
|
} else if (resultCode != RESULT_OK) {
|
||||||
LogUtils.d(TAG, "操作取消或失败,requestCode: " + requestCode);
|
LogUtils.d(TAG, "操作取消或失败,requestCode: " + requestCode);
|
||||||
|
|||||||
Reference in New Issue
Block a user