1

在我的网络服务中,图像以 byteArray 格式存储。我想转换位图图像。

我在这里附上了我的代码。

  BufferedInputStream bufferedInputStream = new BufferedInputStream(AndroidJSONParsingActivity.inputStream);
             Bitmap bmp = BitmapFactory.decodeStream(bufferedInputStream);
             ByteArrayOutputStream companylogo = new
             ByteArrayOutputStream();
             ImageView image=new ImageView(this);
             image.setImageBitmap(bmp);
4

2 回答 2

2
Bitmap bitmap = BitmapFactory.decodeFile("/path/images.jpg");
ByteArrayOutputStream blob = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 0 /*ignored for PNG*/, blob);
byte[] bitmapdata = blob.toByteArray();
//if bitmapdata is the byte array then getting bitmap goes like this

Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapdata , 0, bitmapdata .length);
Returns The decoded bitmap, or null if the image could not be decode.
于 2013-04-15T07:41:18.073 回答
1

尝试这个,

// Camera arg conversion to Bitmap
Bitmap background = BitmapFactory.decodeByteArray(Your_byte_array_image, 0,
                            Your_byte_array_image.length);
Bitmap back = Bitmap.createBitmap(background.getWidth(),
                        background.getHeight(), Bitmap.Config.ARGB_8888);

使用此位图。

于 2013-04-15T07:44:58.530 回答