android - 调整大小并保存图像
问题描述
我正在使用 Glide 4.7.1 尝试调整大小并保存一些照片。
for (String path : this.paths) {
Glide.with(this.context).asBitmap().load(path).apply(RequestOptions.fitCenterTransform()).into(new SimpleTarget<Bitmap>(1080, 1920) {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
try {
resource.compress(Bitmap.CompressFormat.JPEG, 85, new FileOutputStream(MasterFacade.getAppDir() + "temp/" + resource.hashCode() + ".jpg"));
listener.onUpdate(progressMessage, processed.get());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
});
}
我只想将大小(保持纵横比)调整为 1080x1920(或最接近的),然后将新位图保存到文件中。
我确定我有权写我确定path
图像存在我确定MasterFacade.getAppDir() + "temp/" + resource.hashCode() + ".jpg"
是一个有效的目录并且我已经在上面写了权限
但是这个代码永远达不到!
我尝试调试,但从onResourceReady
未被调用...
我究竟做错了什么?
解决方案
在 Glide 4.x 中使用此调整图像大小
Glide.with(getContext())
.load(imagePath)
.apply(new RequestOptions().override(600, 200))
.fitCenter()
.into(setImage);
推荐阅读
- xamarin - 是否可以使用 Xamarin 开发 Fleetboard 应用程序?
- c# - ShowDialog 上的自定义用户控制按钮背景颜色更改
- python - 如何减少python的最小内存使用量
- excel - 我的 VBA 函数在尝试运行时返回值错误
- css - Yii2 覆盖 bootstrap.css / bootstrap.min.css
- firebase-authentication - 如何通过将相同的 otp 发送到电子邮件以及电话号码来验证用户以允许使用 azure adb2c 用户流进行注册
- python - 使用 PIL.resize 调整 JPG 大小会得到一个完全黑色的图像
- database - MarkLogic - 如何知道数据库的大小、索引的大小、总索引
- flutter - Flutter 屏幕尺寸计算
- php - 当我从数据库中删除一行时,我还想从文件夹中删除相应的文件