2013-07-29 1 views
0

JSON 형식의 웹 서비스를 통해 이미지가 전송되었습니다. 다음은 보이는 모양의 스 니펫입니다. { "notif_detailsResult": [{ "image": [255,216,255,224,0,16,74, ....
Android의 Imageview에서 이미지를 표시하고 싶습니다. 파싱 ​​json으로 후, 나는 문자열Android에서 Blob/Varbinary ti 이미지 변환

@Override 
protected String doInBackground(String... params) { 

String epc = params[0]; 
String result = null; 
String url = "http://192.168.142.1:90/Service1.svc/notif?notif_id=24"; 
try { 

BufferedReader inStream = null; 
HttpClient httpClient = new DefaultHttpClient(); 
HttpGet httpR = new HttpGet(url); 
httpR.setHeader("Accept", "application/json"); 
httpR.setHeader("Content-type", "application/json"); 
HttpResponse response = httpClient.execute(httpR); 
System.out.println("HERE in product display after exectunig response"); 
inStream = new BufferedReader(new  InputStreamReader(response.getEntity().getContent())); 
StringBuffer sb = new StringBuffer(""); 
String line = ""; 
String NL = System.getProperty("line.separator"); 
while((line = inStream.readLine()) != null) 
{ 
sb.append(line + NL) ; 
} 
inStream.close(); 
result = sb.toString(); 

} catch(Exception e){ 
e.printStackTrace(); 
} 
return result; 
} 

@Override 
protected void onPostExecute(String result) { 

super.onPostExecute(result); 
try { 

JSONObject jObject = new JSONObject(result); 

JSONArray array = jObject.getJSONArray("notif_detailsResult"); 
JSONObject jObject1 = array.getJSONObject(0); 


String data = jObject1.getString("image"); 
+0

이미지 값이 Base64 문자열 형식 또는 byte []입니까? – Srinivasan

+0

이미지를 삽입하는 데 사용한 쿼리입니다. 업데이트 dbo.notification 설정 이미지 = (선택 BulkColumn OPENROWSET ( \t \t \t 대량 'D : \ Steelcase는 이미지 \ 블루 Chair.jpg'에서 SINGLE_BLOB) AS BLOB) 곳 notification_id = '24'; – SMR

+0

그래서, 저는 이것이 Byte 포맷이라고 생각합니다! – SMR

답변

0

의 이미지 값을 저장하면 "데이터"변수 오른쪽 이미지가 드리려고 같은 작업을 수행 할 수 있습니까? 그 다음 객체로 이미지 값을 얻을 수 있습니다 [바이트 위치의 경우 은 이제 ..

byte[] outImage=data;//do required thing to parse into byte if needed 
ByteArrayInputStream imageStream = new ByteArrayInputStream(outImage); 
Bitmap theImage = BitmapFactory.decodeStream(imageStream); 
imgView.setImageBitmap(theImage); 
0

을 [] 바이트로 문자열을 구문 분석합니다.

보십시오.

+0

JSON 형식의 결과는 다음과 같습니다. { "notif_detailsResult": [{ "image": [255,216,255,224,0,16,74, .... 위의 코드는 작동하는 것처럼 보입니다 :(내 데이터 유형은 DB는 Varbinary이고 BLOB 객체를 사용하여 이미지를 저장합니다. – SMR