如何接收的字节数组并将其转换成图像中的Android? [英] How to receive a byte array and convert it to image in Android?
本文介绍了如何接收的字节数组并将其转换成图像中的Android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用:
InputStream in;
Bitmap bmp=BitmapFactory.decodeStream(in);
但过程等待时间长,没有任何反应。在服务器端,我有图像转换成字节[]。
but the process waits for a long time and nothing happens. On the server side, i have the image converted into byte[].
推荐答案
我觉得这块code将是对您有用:
I think this piece of code will be useful for you:
public Bitmap DownloadImage(String url)
{
HttpClient client = new DefaultHttpClient();
HttpResponse httpResponse;
Bitmap bmp = null;
try{
httpResponse = client.execute(new HttpGet(url));
responseCode = httpResponse.getStatusLine().getStatusCode();
HttpEntity entity = httpResponse.getEntity();
if (entity != null)
{
InputStream in = entity.getContent();
bmp = BitmapFactory.decodeStream(in);
in.close();
}
} catch (ClientProtocolException e) {
client.getConnectionManager().shutdown();
e.printStackTrace();
} catch (IOException e) {
client.getConnectionManager().shutdown();
e.printStackTrace();
}
return bmp;
}
这篇关于如何接收的字节数组并将其转换成图像中的Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文