32

入力ストリームをWebからビットマップに変換する際に問題があります。問題は、入力イメージタイプが.BMP(ビットマップ)の場合にのみ発生します。その場合:bitmapFactory.decodeStreamはヌルを返します。入力ストリームをビットマップに変換する

この問題を解決する方法や、デバッグを続行する必要があることを示すヒントはありますか?

プラットフォーム:アンドロイド(ハニカム)

URLConnection conn = url.openConnection(); 
conn.connect(); 

inputStream = conn.getInputStream(); 

bufferedInputStream = new BufferedInputStream(inputStream); 

bmp = BitmapFactory.decodeStream(bufferedInputStream); 
+1

を助けることができるよりも、任意のログエラーがありますか? –

答えて

41

は、ログからのポイントのためにあなたに@Amirをありがとうございます。発見された行:

decoder->decode returned false 

これはよくある問題です。私は解決策を見つけた。

私の以前のコード:

URLConnection conn = url.openConnection(); 
conn.connect(); 

inputStream = conn.getInputStream(); 

bufferedInputStream = new BufferedInputStream(inputStream); 

bmp = BitmapFactory.decodeStream(bufferedInputStream); 

取り組んでいるコード:

HttpGet httpRequest = null; 

try { 
    httpRequest = new HttpGet(url.toURI()); 
} catch (URISyntaxException e) { 
    e.printStackTrace(); 
} 

HttpClient httpclient = new DefaultHttpClient(); 

HttpResponse response = (HttpResponse) httpclient.execute(httpRequest); 

HttpEntity entity = response.getEntity(); 

BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity); 

InputStream instream = bufHttpEntity.getContent(); 

bmp = BitmapFactory.decodeStream(instream); 

Source

+0

どのサービスをお使いですか? –

+0

私はWCFサービスを使用していますが、画像のbyte []を送信してメソッドを使用してビットマップ画像に戻しましたが、BitmapFactory.decodeStream(instream)は常にnullです。 –

関連する問題