Does glide load bitmap or byte array ?

Glide load bitmap or byte array?

Glide load bitmap and byte array. It depends on your needs and what you want to load using the glide library. Both have their own advantages and disadvantages.

Loading bitmaps can be more resource-intensive since they require more memory. However, they can be more easily compressed and can be displayed more quickly.

Loading byte arrays can be less resource-intensive, but they can be more difficult to compress and can take longer to display.

 

 

Supported formats

Glide supports PNG, GIF, RAW, JPEG, and WEBP.

For more info check out the code of supported file formats for Glide.

 

 

How we can load bitmap using Glide

GlideApp.with(getContext())
        .asBitmap()
        .load("Image uri")
        .into(new SimpleTarget<Bitmap>() {
            @Override
            public void onResourceReady(Bitmap bitmap, Transition<? super Bitmap> transition) {
                 
              }
            });
        }

 

 

How we can load byte arrays using Glide

Assume that you have a base64 string

String imgBytes = "HoAao14FpmtHSev3OgsrQNsawkFzXNcY3BsfQl6a...."

Then you have to convert imgBytes String to an array of bytes using the below code

byte[] imgByteArray = Base64.decode(imgBytes, Base64.DEFAULT);

After that pass this imgByteArray to Glide-like this.

Glide.with(getContext())
    .load(imgByteArray)
    .asBitmap()
    .placeholder(R.drawable.bytedemo)
    .into(byteDemoImageView);

 

Also, read java tutorials.

 

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *