Android Glide无法解析为位图()

Android Glide无法解析为位图(),android,android-glide,Android,Android Glide,为什么在使用Glide时无法解析此方法?我也无法解析.diskstaretegy(): 对于asBitmap,您需要按如下方式编写: Glide.with(getActivity()).asBitmap().load(chalet.profilePhoto).into(mImageView); 你可以这样换一种方式 RequestOptions requestOptions = new RequestOptions(); requestOptions.placeholder(R.drawabl

为什么在使用
Glide
时无法解析此方法?我也无法解析
.diskstaretegy()


对于asBitmap,您需要按如下方式编写:

Glide.with(getActivity()).asBitmap().load(chalet.profilePhoto).into(mImageView);

你可以这样换一种方式

RequestOptions requestOptions = new RequestOptions();
requestOptions.placeholder(R.drawable.ic_placeholder);
requestOptions.diskCacheStrategy(DiskCacheStrategy.ALL)
requestOptions.error(R.drawable.ic_error);

Glide.with(context)
     .setDefaultRequestOptions(requestOptions)
     .asBitmap()
     .load(url).into(holder.imageView);
//将asBitmap()放在Glide.with(context)之后,,。4.0+
//对于子采样ScaleImageView,请使用SimpleTarget
带(上下文)滑动
.asBitmap()
.加载(图像[位置])
.apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.AUTOMATIC))
.into(新的SimpleTarget(宽度、高度){
@凌驾

public void onResourceReady(位图位图,转换我找到了修复它的方法,您必须在
with()
之后添加
asBitmap()
,它将像以前一样工作

PS:我的Glide版本是4.7.1

load()之前调用
asBitmap()

Glide.with(getActivity()).asBitmap()
.荷载(水头)
.listener(新的RequestListener(){
@凌驾
public boolean onload失败(@Nullable e,对象o,目标,布尔值b){
//Toast.makeText(cxt,getResources().getString(R.string.意外错误\u发生\u重试),Toast.LENGTH\u SHORT.show();
返回false;
}
@凌驾
公共布尔onResourceReady(位图、对象o、目标、数据源数据源、布尔b){
if(null==标题)
返回false;
//设置图像
header.setImageBitmap(位图);
//处理位图
调色板.from(位图).generate(
新建Palette.PaletteSyncListener(){
@抑制警告(“资源类型”)
@凌驾
已生成的公共空心板(调色板){
int vibrantColor=调色板
.getVibrantColor(R.color.primary_500);
int vibrantDarkColor=调色板
.getDarkVibrantColor(R.color.primary_700);
折叠工具栏布局
.setContentScrimColor(vibrantColor);
折叠工具栏布局
.setStatusBarScrimColor(vibrantDarkColor);
}
});
返回false;
}
}
).submit();

如果出现错误,请按照以下步骤操作

在滑动库中,将
.asBitmap()
移动到
.load()之前

---------------------或-----------------------

    Glide.with(context)
        .setDefaultRequestOptions(requestOptions)
        .asBitmap()
        .load(url)
        .into(holder.imageView);

那么
.diskCacheStrategy(diskCacheStrategy.ALL)
&
.fitCenter()
&
.dontAnimate()呢
?@TimCastelijns,这是V3如何重新加载缓存数据的文档?我不明白,你的意思是什么?你上面的代码只是将图像添加到缓存中,对吗?我如何从缓存中再次加载而不是再次下载它?Glide版本4.10.0对我来说很好
RequestOptions requestOptions = new RequestOptions();
requestOptions.placeholder(R.drawable.ic_placeholder);
requestOptions.diskCacheStrategy(DiskCacheStrategy.ALL)
requestOptions.error(R.drawable.ic_error);

Glide.with(context)
     .setDefaultRequestOptions(requestOptions)
     .asBitmap()
     .load(url).into(holder.imageView);
// Put asBitmap() right after Glide.with(context)   ,,. 4.0+
// And for SubsamplingScaleImageView use SimpleTarget

  Glide.with(context)
                .asBitmap()
                .load(images[position])
                .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.AUTOMATIC))
                .into(new SimpleTarget<Bitmap>(width, height) {
                    @Override
                    public void onResourceReady(Bitmap bitmap, Transition<? super Bitmap> transition) {
                        subsampleImageView.setImage(ImageSource.bitmap(bitmap)); //For SubsampleImage
                    }
                });
Glide.with(context)
 .asBitmap()
 .load(uri)
        Glide.with(getActivity()).asBitmap()
                .load(headerURl)
                .listener(new RequestListener<Bitmap>() {
                              @Override
                              public boolean onLoadFailed(@Nullable GlideException e, Object o, Target<Bitmap> target, boolean b) {
//                                  Toast.makeText(cxt,getResources().getString(R.string.unexpected_error_occurred_try_again),Toast.LENGTH_SHORT).show();
                                  return false;
                              }

                              @Override
                              public boolean onResourceReady(Bitmap bitmap, Object o, Target<Bitmap> target, DataSource dataSource, boolean b) {
                                  if (null == header)
                                      return false;

                                 //set image
                                  header.setImageBitmap(bitmap);

                                  //process bitmap
                                  Palette.from(bitmap).generate(
                                          new Palette.PaletteAsyncListener() {
                                              @SuppressWarnings("ResourceType")
                                              @Override
                                              public void onGenerated(Palette palette) {

                                                  int vibrantColor = palette
                                                          .getVibrantColor(R.color.primary_500);
                                                  int vibrantDarkColor = palette
                                                          .getDarkVibrantColor(R.color.primary_700);
                                                  collapsingToolbarLayout
                                                          .setContentScrimColor(vibrantColor);
                                                  collapsingToolbarLayout
                                                          .setStatusBarScrimColor(vibrantDarkColor);
                                              }
                                          });
                                  return false;
                              }
                          }
                ).submit();
    Glide.with(context)
        .setDefaultRequestOptions(requestOptions)
        .asBitmap()
        .load(url)
        .into(holder.imageView);