Using Glide to load bitmap into ImageView

后端 未结 4 1346
天涯浪人
天涯浪人 2020-12-05 11:38

How can i use Glide library to load Bitmap into my ImageView? I want to create a custom image with text and load it into imageview using Glide.

This

4条回答
  •  無奈伤痛
    2020-12-05 12:27

    I don't know performance, but you can try this:

    First of all transform your bitmap as byte[] array:

    private byte[] bitmapToByte(Bitmap bitmap){
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
        byte[] byteArray = stream.toByteArray();
        return byteArray;
    }
    

    Then use glide in this way:

    Glide.with(holder.imagePhoto.getContext()).load(bitmapToByte(yourBitmap)).asBitmap().override(300, 300).fitCenter().into(holder.imagePhoto);
    

    In your case:

    Glide.with(holder.imagePhoto.getContext()).load(bitmapToByte(yourBitmap)).asBitmap().into(holder.imagePhoto); //>>not tested
    

提交回复
热议问题