Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Glide:在加载实际图像之前显示模糊图像_Android_Android Glide - Fatal编程技术网

Android Glide:在加载实际图像之前显示模糊图像

Android Glide:在加载实际图像之前显示模糊图像,android,android-glide,Android,Android Glide,我正在开发一个Android应用程序,向用户显示全屏图像。图像是从服务器获取的。我正在使用Glide显示图像。但是我想在显示实际图像之前显示一个非常小的模糊图像。缓存图像后,应直接显示全尺寸图像 图像显示流程如下所示: -如果是第一次下载图像,请先下载小比例图像,然后下载全分辨率图像。 -如果以前下载过图像,请直接显示全尺寸图像 我在Glide库中找不到任何方法,可以告诉我缓存中是否存在文件 任何想法,如何做到这一点 用于加载图像的下采样版本。然后加载较大的图像,并使用 希望这对你有帮助!干杯

我正在开发一个Android应用程序,向用户显示全屏图像。图像是从服务器获取的。我正在使用Glide显示图像。但是我想在显示实际图像之前显示一个非常小的模糊图像。缓存图像后,应直接显示全尺寸图像

图像显示流程如下所示: -如果是第一次下载图像,请先下载小比例图像,然后下载全分辨率图像。 -如果以前下载过图像,请直接显示全尺寸图像

我在Glide库中找不到任何方法,可以告诉我缓存中是否存在文件

任何想法,如何做到这一点

用于加载图像的下采样版本。然后加载较大的图像,并使用


希望这对你有帮助!干杯

使用BitmapFactory.Options.inSampleSize制作图像的下采样版本,并上载两个版本。加载示例图像(这将花费更少的时间),下载更大的版本时,切换到该版本。您还可以使用TransitionDrawable进行淡入淡出过渡。

更好的方法是,您可以从这个库中获得想法或使用这个库

2种在Android中进行模糊和原始图像处理的方法

1) 最初加载模糊图像服务器URL路径,一旦获得成功,位图缓存机制将加载原始(大)图像服务器URL路径

第1点是可能的,我为您得到了答案(请您的服务器团队获取模糊图像或低质量图像以进行模糊,然后加载大图像)。

Glide.with(mContext)
.load(image.getmedia())
.asBitmap()
.diskCacheStrategy(diskCacheStrategy.ALL)
.into(新的SimpleTarget(){
@凌驾
public void onResourceReady(位图、动画){
//在这里用位图做些什么。
holder.thumbnail.setImageBitmap(位图);
Log.e(“GalleryAdapter”、“Glide getMedium”);
使用(mContext)滑动
.load(image.getLarge())
.asBitmap()
.diskCacheStrategy(diskCacheStrategy.ALL)
.into(新的SimpleTarget(){
@凌驾
public void onResourceReady(位图、动画){
//在这里用位图做些什么。
holder.thumbnail.setImageBitmap(位图);
Log.e(“GalleryAdapter”、“Glide getLarge”);
}
});
}
});
2) Facebook的Fresco是Android的一个新图像库。这是介绍图书馆的官方博客。它支持通过网络传输渐进式JPEG图像,这对于通过慢速连接显示大型图像非常有帮助。人们可以看到图像的质量逐渐提高

这不是一个完美的方法,但它将是最简单的方法

将占位符图像设置为模糊,并将其设置为滑动。然后,它将始终显示模糊图像,然后在加载实际图像后,它将显示。

您可以参考此代码来使用glide

//crete this method into your Utils class and call this method wherever you want to use.
//you can set these placeHolder() and error() image static as well. I made it as comment inside this method, then no need to use [placeHolderUrl and errorImageUrl] parameters. remove it from this method.
public static void loadImage(final Activity context, ImageView imageView, String url, int placeHolderUrl, int errorImageUrl) {
    if (context == null || context.isDestroyed()) return;

    //placeHolderUrl=R.drawable.ic_user;
    //errorImageUrl=R.drawable.ic_error;
        Glide.with(context) //passing context 
                .load(getFullUrl(url)) //passing your url to load image.
                .placeholder(placeHolderUrl) //this would be your default image (like default profile or logo etc). it would be loaded at initial time and it will replace with your loaded image once glide successfully load image using url.
                .error(errorImageUrl)//in case of any glide exception or not able to download then this image will be appear . if you won't mention this error() then nothing to worry placeHolder image would be remain as it is.
                .diskCacheStrategy(DiskCacheStrategy.ALL) //using to load into cache then second time it will load fast.
                .animate(R.anim.fade_in) // when image (url) will be loaded by glide then this face in animation help to replace url image in the place of placeHolder (default) image.
                .fitCenter()//this method help to fit image into center of your ImageView 
                .into(imageView); //pass imageView reference to appear the image.
}
使用Glide v4:

Glide.with(context)
    .load(URL)
    .thumbnail(0.1f)
    .into(image_view)

glide有一种直接的方法:

val thumbnailRequest = Glide.with(this)
        .load("https://picsum.photos/50/50?image=0")

Glide.with(this)
        .load("https://picsum.photos/2000/2000?image=0")
        .thumbnail(thumbnailRequest)
        .into(imageThumbnail)
从:

缩略图是一种动态占位符,可以从Internet加载。在加载和处理实际请求之前,将显示获取的缩略图。如果由于某种原因缩略图出现在原始图像之后,它将被取消


您的服务器上必须有一个小尺寸和全尺寸的映像。如果使用Firebase作为后端,则可以使用。一旦您有了一个小尺寸的图像URL和一个全尺寸的图像URL,您就可以像这样使用Glide:

            Glide.with(context)
            .load(fullSizeImageUrl)          
            .thumbnail(
                Glide.with(context)
                    .load(smallSizeImageUrl)
            ).into(imageView)
当小尺寸图像变得模糊时,您将获得模糊效果

根据Glide文档: .缩略图() 加载并显示给定缩略图请求检索到的资源(如果它在此请求之前完成)。最好用于加载比全尺寸资源更小且加载速度更快的缩略图资源。无法保证请求实际完成的顺序。但是,如果thumb请求在完整请求之后完成,thumb资源将永远不会替换完整资源


但是在这种情况下,我需要下载大图像,在图像下载之前我将没有任何显示\You's great boss…:)@Hiren我得到了一个
无法解析方法“override(int,int)”的答案,谢谢:)你确定它不会下载整个图像然后缩小它吗?
val thumbnailRequest = Glide.with(this)
        .load("https://picsum.photos/50/50?image=0")

Glide.with(this)
        .load("https://picsum.photos/2000/2000?image=0")
        .thumbnail(thumbnailRequest)
        .into(imageThumbnail)
            Glide.with(context)
            .load(fullSizeImageUrl)          
            .thumbnail(
                Glide.with(context)
                    .load(smallSizeImageUrl)
            ).into(imageView)