3

我正在使用 Parse SDK 来构建我的应用程序。

通过使用 Intents,我可以轻松地从图库中获取位图。我想将它们用作我的用户的个人资料图片。

但是,为了上传它,我必须将它转换为字节数组。此外,当我下载它时,它以字节数组的形式出现,我必须将它转换回 Drawable。

为了将其转换为字节数组,我这样做:

public static byte[] bitmapToByteArray(Bitmap bmp)
{
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
    byte[] byteArray = stream.toByteArray();
    return byteArray;
}

我找不到如何将此字节 [] 转换回位图而不必先保存它。这个过程如何实现?

4

2 回答 2

6

只需执行以下操作:

Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
于 2012-08-31T11:15:07.147 回答
2
  Bitmap  bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
于 2012-08-31T11:14:54.230 回答