How to create a Drawable from byte[] ? (Android)

前端 未结 2 1342
春和景丽
春和景丽 2020-12-14 18:48

I have an array of bytes and I need to convert it into a Android Drawable. How can I perform this conversion?

Here is what i tried but without success:



        
2条回答
  •  青春惊慌失措
    2020-12-14 19:16

    If your byte[] b is contains imagedata then you can also try this,

     Drawable image = new BitmapDrawable(BitmapFactory.decodeByteArray(b, 0, b.length));
    

    EDIT

    BitmapDrawable constructor without Resources is now deprecated, So use this instead:

    Drawable image = new BitmapDrawable(getResources(),BitmapFactory.decodeByteArray(b, 0, b.length));
    

    Try this and let me know what happen,

提交回复
热议问题