如何创建byte []的一个绘制对象? (安卓) [英] How to create a Drawable from byte[] ? (Android)

查看:406
本文介绍了如何创建byte []的一个绘制对象? (安卓)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字节数组,我需要将其转换成Android的绘制对象。我该如何进行这种转换?

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:

byte[] b = getByteArray();
ByteArrayInputStream is = new ByteArrayInputStream(b);
Drawable drw = Drawable.createFromStream(is, "articleImage");

DRW总是空!

drw is always null!

编辑:

我的byte []的实际损坏的/不完整的,这就是问题。

My byte[] was actually corrupted/incomplete, that was the problem.

推荐答案

如果你的字节[] b 是包含的ImageData那么你也可以试试这个,

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

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

试试这个,让我知道发生什么事,

Try this and let me know what happen,

这篇关于如何创建byte []的一个绘制对象? (安卓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆