2013-04-15 163 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

相關問題