http 応答から画像を取得しようとしていますが、ストリームをビットマップに変換できません。ここで何が欠けているのか教えてください。
参考までに - 画像コンテンツは生のバイナリと jpeg 画像として受信されます。
手順は次のとおりです。
- HttpRequest を作成します。
- 応答で 200 を確認します -> httpentity コンテンツを取得します。
- BitMap factory を使用してストリームをビットマップに変換します。
- ビットマップをイメージビューに設定します
AsyncTask の postExecute でこれを行う
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(endpoint);
// Adding Headers ..
// Execute the request
HttpResponse response;
try {
response = httpclient.execute(httpget);
if (response.getStatusLine().getStatusCode() == 200) {
// Get hold of the response entity
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
return instream;
// instream.close();
}
}
}
AsyncTask の postExecute でこれを行う
if (null != instream) {
Bitmap bm = BitmapFactory.decodeStream(instream);
if(null == bm){
Toast toast = Toast.makeText(getApplicationContext(),
"Bitmap is NULL", Toast.LENGTH_SHORT);
toast.show();
}
ImageView view = (ImageView) findViewById(R.id.picture_frame);
view.setImageBitmap(bm);
}
前もって感謝します。