在将字节数组转换为位图时遇到问题

时间:2018-12-13 05:55:13

标签: android android-studio native

我的代码

 String passenger_sign = assignedJobJson.getJSONObject(position).getString("passenger_sign");
        Log.e(TAG, "passenger_sign: "+passenger_sign );


        byte[] Bytedata = passenger_sign.getBytes();
        Log.e(TAG, "Bytedata: "+Bytedata );

        ByteArrayInputStream arrayInputStream = new ByteArrayInputStream(Bytedata);
        Bitmap bitmap = BitmapFactory.decodeStream(arrayInputStream);
        //Bitmap bmp = BitmapFactory.decodeByteArray(Bytedata, 0, Bytedata.length);
        Log.e(TAG, "bitmap: "+bitmap );

问题

  1. 我想将字节数组转换为位图,但在转换为位图时仅显示空值。

1 个答案:

答案 0 :(得分:0)

假设您的passenger_sign包含在Base64中转换的图像数据,则可以应用以下代码:

byte[] decodedString = Base64.decode(passenger_sign, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
// Now, we set the decoded bytes to an image view to check if conversion is successfull
imageView.setImageBitmap(decodedByte);
相关问题