Android 调整大小并保存图像
我正在使用Glide 4.7.1尝试调整大小并保存一些照片Android 调整大小并保存图像,android,image,bitmap,android-glide,Android,Image,Bitmap,Android Glide,我正在使用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 publi
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();
}
}
});
}
for(字符串路径:this.paths){
Glide.with(this.context).asBitmap().load(path).apply(RequestOptions.fitCenterTransform()).into(新SimpleTarget(108011920){
@凌驾
public void onResourceReady(@NonNull Bitmap resource,@Nullable Transition您可以使用override
函数通过滑动调整图像大小
你可以从中得到更多
如:
public static void loadCircularImageGlide(String imagePath, ImageView view) {
Glide.with(view.getContext())
.load(imagePath)
.asBitmap()
.override(1080,1920) // resizes the image to these dimensions (in pixel). resize does not respect aspect ratio
.error(R.drawable.create_timeline_placeholder)
.fitCenter() // scaling options
.transform(new CircularTransformation(view.getContext())) // Even you can Give image tranformation too
.into(view);
}
您可以使用override
功能通过滑动调整图像大小
你可以从中得到更多
如:
public static void loadCircularImageGlide(String imagePath, ImageView view) {
Glide.with(view.getContext())
.load(imagePath)
.asBitmap()
.override(1080,1920) // resizes the image to these dimensions (in pixel). resize does not respect aspect ratio
.error(R.drawable.create_timeline_placeholder)
.fitCenter() // scaling options
.transform(new CircularTransformation(view.getContext())) // Even you can Give image tranformation too
.into(view);
}
问题似乎是由路径引起的,在“滑动”中,如果要从外部内存加载图像,必须使用正确的路径
确保路径有效
String path="file://"+"image path";
for (String path : this.paths) {
Glide.with(this.context).asBitmap().load("file://"+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();
}
}
});
}
String path=“文件:/”+“图像路径”;
for(字符串路径:this.paths){
Glide.with(this.context).asBitmap().load(“文件:/”+path).apply(RequestOptions.fitCenterTransform()).into(新SimpleTarget(108011920){
@凌驾
public void onResourceReady(@NonNull Bitmap resource,@Nullable Transition问题似乎是由路径引起的,在Glide中,如果要从外部内存加载图像,必须使用正确的路径
确保路径有效
String path="file://"+"image path";
for (String path : this.paths) {
Glide.with(this.context).asBitmap().load("file://"+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();
}
}
});
}
String path=“文件:/”+“图像路径”;
for(字符串路径:this.paths){
Glide.with(this.context).asBitmap().load(“文件:/”+path).apply(RequestOptions.fitCenterTransform()).into(新SimpleTarget(108011920){
@凌驾
public void onResourceReady(@NonNull Bitmap resource,@Nullable Transition您可以使用glide调整图像大小。试试看
Glide.with(getContext())
.load(图像路径)
.apply(新请求选项().override(600200))
.fitCenter()
.into(setImage);
您可以使用glide调整图像大小。请尝试
Glide.with(getContext())
.load(图像路径)
.apply(新请求选项().override(600200))
.fitCenter()
.into(setImage);
我相信没有一个答案能真正理解我的问题:
我尝试过调试,onResourceReady从未被调用过…
所以我查看了glide wiki,它说:
第二个关键部分是glidebuilder行
这里的问题实际上是Glide的一个特性:当您传递上下文时,
例如,当前应用程序活动Glide将自动停止
请求活动停止时的请求
我在调用活动上的finish()
之后立即调用了上面的代码,因此Glide在内部停止了代码,没有引发任何异常,并且从未调用过onResourceReady
。我相信没有一个答案真正理解我的问题:
我尝试过调试,onResourceReady从未被调用过…
所以我查看了glide wiki,它说:
第二个关键部分是glidebuilder行
这里的问题实际上是Glide的一个特性:当您传递上下文时,
例如,当前应用程序活动Glide将自动停止
请求活动停止时的请求
我在调用活动上的finish()
之后立即调用了上面的代码,因此Glide在内部停止了该代码,没有引发任何异常,并且从未调用过onResourceReady
。在Glide 4.x中使用该代码调整图像大小
Glide.with(getContext())
.load(imagePath)
.apply(new RequestOptions().override(600, 200))
.fitCenter()
.into(setImage);
在Glide 4.x中使用此选项调整图像大小
Glide.with(getContext())
.load(imagePath)
.apply(new RequestOptions().override(600, 200))
.fitCenter()
.into(setImage);
按照@Gautam Kumar的方式获取图像,但您还必须通过添加android:adjustViewBounds=“true”来更改XML中的imageView
Glide.with(getContext())
.load(图像路径)
.apply(新请求选项().override(600200))
.into(setImage);
然后是XML
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:id="@+id/image_id"
android:src="@drawable/ic_image" />
按照@Gautam Kumar所做的操作获取图像,但您还必须通过添加android:adjustViewBounds=“true”来更改XML中的imageView
Glide.with(getContext())
.load(图像路径)
.apply(新请求选项().override(600200))
.into(setImage);
然后是XML
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:id="@+id/image_id"
android:src="@drawable/ic_image" />
路径和特定路径的值是什么?请在此共享任何路径您需要检查:@MayurPatel,不再工作,我甚至不能调用asGif()
调用load后,必须before@quicklearner,this.paths
是一组文件,如:/sdcard/DCIM/Camera/100_0306_20180122200616.jpg
路径和特定路径的值是什么?请在此处共享任何路径您需要检查的内容:@MayurPatel,不再工作,我甚至无法调用asGif()
调用load后,必须before@quicklearner,this.paths
是一组文件,如:/sdcard/DCIM/Camera/100_0306_20180122200616.jpg
不适用于glide 4.7.1…覆盖(x,y)
根本不存在anymore@RafaelLima您必须检查该文档是否存在4.7.1中的覆盖方法。对于glide 4.7.1不起作用…override(x,y)
甚至不存在anymore@RafaelLima您必须检查该文件是否存在4.7.1中的覆盖方法。