使用以下代码时:
GlIDe.with(getActivity()) .load(images.get(i)) .asBitmap().centerCrop() .into(new SimpleTarget<Bitmap>(1200,1200) { @OverrIDe public voID onResourceReady(Bitmap resource,GlIDeAnimation glIDeAnimation) { } });
每个位图都会调整大小到指定的尺寸.因此,如果图像是400×300,它会升级到1200 x 1200,这是我不想要的.如何使图像小于指定的尺寸,它不会调整大小?
我正在指定尺寸,因为我想要考虑到centerCrop来调整大于指定尺寸的每个图像的大小;然后如果图像小于指定的尺寸,我不希望它的大小调整.
解决方法I want every image that’s bigger than the specifIEd dimensions to be
resized taking into account centerCrop; and then if the image is
smaller than the specifIEd dimensions,I don’t want it to be resized.
您可以使用自定义转换获取此行为:
public class CustomCenterCrop extends CenterCrop { public CustomCenterCrop(BitmapPool bitmapPool) { super(bitmapPool); } public CustomCenterCrop(Context context) { super(context); } @OverrIDe protected Bitmap transform(BitmapPool pool,Bitmap totransform,int outWIDth,int outHeight) { if (totransform.getHeight() > outHeight || totransform.getWIDth() > outWIDth) { return super.transform(pool,totransform,outWIDth,outHeight); } else { return totransform; } }}
然后像这样使用它:
GlIDe.with(getActivity()) .load(images.get(i)) .asBitmap() .transform(new CustomCenterCrop(getActivity())) .into(new SimpleTarget<Bitmap>(1200,GlIDeAnimation glIDeAnimation) { } });总结
以上是内存溢出为你收集整理的android – 如何停止Glide upscaling?全部内容,希望文章能够帮你解决android – 如何停止Glide upscaling?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)