Android上的ParseFile

时间:2012-08-31 11:12:11

标签: android parsing

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

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

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

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

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

我无法找到如何将此byte []转换回Bitmap而不必先保存它。如何实现这一过程?

2 个答案:

答案 0 :(得分:6)

请执行以下操作:

Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);

答案 1 :(得分:2)

  Bitmap  bmp = BitmapFactory.decodeByteArray(data, 0, data.length);