gpt4 book ai didi

android - 使用 Picasso、Glide、Image Loader、Universal Image Loader 加载图像失败

转载 作者:行者123 更新时间:2023-11-29 00:51:33 28 4
gpt4 key购买 nike

i have creating Hindi video song application, but video thumb can't display in video list. (Single image are loaded but multiple image array can't load.)

使用多个图像加载器库但不加载图像:

enter image description here

Glide:

implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'


Glide .with(viewHolder.icon_1.getContext())
.load(((AppModelicon) this.b.get(i)).getThumnail())
.into(viewHolder.icon_1) ;

Glide.with(MainActivity.this)
.load("https://img.youtube.com/vi/EEX_XM6SxmY/mqdefault.jpg")
.placeholder(R.drawable.ic_menu_camera)
.error(R.drawable.ic_menu_gallery)
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
// log exception
Log.e("TAG", "Error loading image", e);
return false; // important to return false so the error placeholder can be placed
}

@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
})
.into(viewHolder.icon_1);

Picasso:

implementation 'com.squareup.picasso:picasso:2.+'

Picasso.get()
.load("https://img.youtube.com/vi/EEX_XM6SxmY/mqdefault.jpg")
.resize(50, 50)
.centerCrop()
.into(viewHolder.icon_1);

using request manager with glide :

RequestManager requestManager = Glide.with(a)
.applyDefaultRequestOptions(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.NONE))
.applyDefaultRequestOptions(RequestOptions.placeholderOf(R.drawable.ic_menu_camera));
requestManager
.applyDefaultRequestOptions(RequestOptions.skipMemoryCacheOf(true));
requestManager.load(pathToFile)
.into(viewHolder.icon_1);

background task method use :

String pathToFile = this.b.get(i).getThumnail();
DownloadImageWithURLTask downloadTask = new DownloadImageWithURLTask(viewHolder.icon_1);
downloadTask.execute(pathToFile);

public class DownloadImageWithURLTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;

public DownloadImageWithURLTask(ImageView bmImage) {
this.bmImage = bmImage;
}

protected Bitmap doInBackground(String... urls) {
String pathToFile = urls[0];
Bitmap bitmap = null;
try {
InputStream in = new java.net.URL(pathToFile).openStream();
bitmap = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return bitmap;
}

protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}

Please help me how to solve this issue.

最佳答案

如果您在 recyclerview 中加载图像,下面的代码可能会帮助您。

@Override
public void onBindViewHolder(final ViewHolder holder, int position)
{
Glide.with(this.context)
.load(urls.get(position))
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(holder.getImage());
}

更多完整教程可以访问https://ledron.github.io/RecyclerView/

关于android - 使用 Picasso、Glide、Image Loader、Universal Image Loader 加载图像失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59099517/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com