2013-04-15 124 views
0

在我的web服务中,图像以byteArray格式存储。我想转换位图图像。将byteArray转换为android中的位图?

我已将此代码附加到此处。

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

回答

1
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. 
0

试试这个,

// 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); 

使用此位图。

+0

我有这么多的字节数组图像如何制作image.for前标识:[137,80,78,71,13,10,26,10,0,0,0,13,73,72,68 ,82,0,0,0,128,0,0,0,128,8,6,0,0,0,195]在我的web服务json格式 – Deepi

+0

这可以帮助你,http://stackoverflow.com/questions/15021526/retrieve -byte-in-android-from-json-webservice http://stackoverflow.com/questions/10403862/java-parse-json-byte-array – Numair

相关问题