1

httpentity が InputStream に画像のバイナリ データを持ち、さらに処理するためにライブラリ ファイル [ String str = EntityUtils.toString(httpResponse.getEntity())] で文字列として変換されているシナリオを用意し、その文字列から入力ストリームを取得しようとしています。

問題を理解するために、以下のシナリオを取り上げます。

動作中 - ImageView がコンテンツとともに表示されます

InputStream inStream = getContentResolver().openInputStream(thisPhotoUri);
Bitmap bm = BitmapFactory.decodeStream(inStream);
ImageView view = (ImageView)findViewById(R.id.picture_frame);
view.setImageBitmap(bm);

問題 - ImageView が画像とともに表示されない

InputStream inStream = getContentResolver().openInputStream(thisPhotoUri);
String str = inStream.toString();
InputStream is = new ByteArrayInputStream(str.getBytes());
Bitmap bm = BitmapFactory.decodeStream(is);
ImageView view = (ImageView)findViewById(R.id.picture_frame);
view.setImageBitmap(bm);
4

3 に答える 3

1

InputStream を String に直接変換することはできません。これが問題かもしれません。

String str = inStream.toString();

これを見て、InputStream を String に変換する方法を特定してください。

于 2014-02-20T10:25:44.643 に答える
-1

これはあなたが探しているものでなければなりません:

InputStream stream = new ByteArrayInputStream(yourString.getBytes("UTF-8"));

于 2014-02-20T10:20:34.133 に答える