android中字节数组转换为位图时遇到的问题



我的代码

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. 我想将字节数组转换为位图,但在转换为位图时只显示null值

假设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);

最新更新