2016-03-24 4 views
1

をビットマップにバイトのJSON配列を変換するために、このどのように私はandroid.iを使用してビットマップイメージにバイトのJSON配列を変換する必要が

{"type":"Buffer","data":[137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,1,140,0,0,1,34,4,3,0,0,0,24,1,248,231,0,0,0,21,80,76,84,69,255,255,255,0,0,0,220,217,207,0,100,0,176,196,222,0,153,204,204,255,255,227,179,150,92,0,0,1,29,73,68,65,84,120,156,237,207,1,13,128,64,12,4,193,211,130,5,44,96,1,11,248,151,192,91,104,66,66,191,153,85,176,147,99,68,249,123,224,155,48,58,181,24,217,62,140,78,205,98,156,165,146,171,84,114,151,74,158,82,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,157,25,187,135,209,169,73,140,9,97,116,106,8,227,5,178,0,69,109,104,207,36,38,0,0,0,0,73,69,78,68,174,66,96,130]} 

この画像のバイト配列のようなJSONレスポンスがDBのpostgresから読み込まれました(タイプ:Bytea)。

バイト配列を実際のイメージに変換する方法。

これは、データ変換

img = profPic.getJSONArray("data"); 
bImage = Base64.decode(img.toString().getBytes(), Base64.DEFAULT); 
bmp = BitmapFactory.decodeByteArray(bImage, 0, bImage.length); 
+0

を試してみているのですか? imgには何がありますか?なぜあなたはJSONArrayをビットマップに変換できるのでしょうか? –

+0

bImageはバイト配列です。json配列format.iのサーバからいくつかのサムネイルを取得していますが、これをバイト配列に変換してからビットマップに変換しようとしています。 –

+0

bImageのコンテンツはどのように見えますか? imgのコンテンツはどのように見えますか? –

答えて

3

bImageに何がこの

JSONObject obj=new JSONObject("{\"type\":\"Buffer\",\"data\":[137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,1,140,0,0,1,34,4,3,0,0,0,24,1,248,231,0,0,0,21,80,76,84,69,255,255,255,0,0,0,220,217,207,0,100,0,176,196,222,0,153,204,204,255,255,227,179,150,92,0,0,1,29,73,68,65,84,120,156,237,207,1,13,128,64,12,4,193,211,130,5,44,96,1,11,248,151,192,91,104,66,66,191,153,85,176,147,99,68,249,123,224,155,48,58,181,24,217,62,140,78,205,98,156,165,146,171,84,114,151,74,158,82,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,157,25,187,135,209,169,73,140,9,97,116,106,8,227,5,178,0,69,109,104,207,36,38,0,0,0,0,73,69,78,68,174,66,96,130]} "); 
Bitmap bitmap=null; 
byte[] tmp=new byte[obj.getJSONArray("data").length()]; 
for(int i=0;i<obj.getJSONArray("data").length();i++){ 
    tmp[i]=(byte)(((int)obj.getJSONArray("data").get(i)) & 0xFF); 
} 
bitmap= BitmapFactory.decodeByteArray(tmp, 0, tmp.length); 
+0

ありがとうございます! –

0

のための私のコードは、これが

byte[] bitmapdata = blob.toByteArray(); 
Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapdata, 0, bitmapdata.length); 
+0

そして 'から? –

関連する問題