如何将byte []转换为drawable?

时间:2013-06-27 09:30:21

标签: android byte drawable

我有一个字节数组,我需要将其转换为Android Drawable。

如何执行此转换?

我试过这个但是行不通:

fileDatabyte[]数组

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

2 个答案:

答案 0 :(得分:2)

尝试this链接。它解释了两种情况,即如何将drawable转换为字节数组,反之亦然。

希望这有助于......:)

答案 1 :(得分:1)

使用此代码

byte[] imageByteArray = cursor.getBlob(cursor
                        .getColumnIndex(SQLiteAdapter.KEY_CONTENT11));

                if (imageByteArray != null) {
                    ByteArrayInputStream imageStream = new ByteArrayInputStream(
                            imageByteArray);
                    Bitmap company_logo = BitmapFactory
                            .decodeStream(imageStream);
                    img_logo.setBackgroundDrawable(null);
                    img_logo.setBackgroundDrawable(new BitmapDrawable(
                            getResources(), company_logo));
                }