Is there a way to load image as bitmap to Glide

后端 未结 11 1445
温柔的废话
温柔的废话 2020-12-04 19:35

Im looking for a way to use bitmap as input to Glide. I am even not sure if its possible. It\'s for resizing purposes. Glide has a good image enhancement with scale. The pro

11条回答
  •  北海茫月
    2020-12-04 19:59

    There is little changes according to latest version of Glide. Now we need to use submit() to load image as bitmap, if you do not class submit() than listener won't be called.

    here is working example i used today.

    Glide.with(cxt)
      .asBitmap().load(imageUrl)
      .listener(new RequestListener() {
          @Override
          public boolean onLoadFailed(@Nullable GlideException e, Object o, Target 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 target, DataSource dataSource, boolean b) {
              zoomImage.setImage(ImageSource.bitmap(bitmap));
              return false;
          }
      }
    ).submit();
    

    It is working and I'm getting bitmap from listener.

提交回复
热议问题