Is there a way to load image as bitmap to Glide

后端 未结 11 1446
温柔的废话
温柔的废话 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:55

    This worked for me in recent version of Glide:

    Glide.with(this)
            .load(bitmap)
            .dontTransform()
            .into(imageView);
    
    0 讨论(0)
  • 2020-12-04 19:56

    For what is is worth, based upon the posts above, my approach:

         Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
    Uri imageUri = Uri.withAppendedPath(sArtworkUri, String.valueOf(album_id));
    

    then in the adapter:

            //  loading album cover using Glide library
    
        Glide.with(mContext)
                .asBitmap()
                .load(imageUri)
                .into(holder.thumbnail);
    
    0 讨论(0)
  • 2020-12-04 19:58

    For version 4 you have to call asBitmap() before load()

    GlideApp.with(itemView.getContext())
            .asBitmap()
            .load(data.getImageUrl())
            .into(new SimpleTarget<Bitmap>() {
                @Override
                public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {}
                });
            }
    

    More info: http://bumptech.github.io/glide/doc/targets.html

    0 讨论(0)
  • 2020-12-04 19:58

    here's another solution which return you a bitmap to set into your ImageView

    Glide.with(this)
                .load(R.drawable.card_front)    // you can pass url too
                .asBitmap()
                .into(new SimpleTarget<Bitmap>() {
                    @Override
                    public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                        // you can do something with loaded bitmap here
    
                        imgView.setImageBitmap(resource);
                    }
                });
    
    0 讨论(0)
  • 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<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) {
              zoomImage.setImage(ImageSource.bitmap(bitmap));
              return false;
          }
      }
    ).submit();
    

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

    0 讨论(0)
  • 2020-12-04 20:03

    This solution is working with Glide V4. You can get the bitmap like this:

    Bitmap bitmap = Glide
        .with(context)
        .asBitmap()
        .load(uri_File_String_Or_ResourceId)
        .submit()
        .get();
    

    Note: this will block the current thread to load the image.

    0 讨论(0)
提交回复
热议问题