我的服务器上有一个ByteArray文件,我想 在ImageView中读取并显示,我该怎么做?将ByteArray文件从服务器转换为imageView中的图像
0
A
回答
0
将您的byteArray转换为位图,然后设置ImageView
的位图。
Bitmap bm = BitmapFactory.decodeByteArray(myByteArray, 0, byteArray.length);//myByteArray is the byte array you want to convert.
ImageView myImage = (ImageView)findViewById(R.id.custom_image);//get a reference to your ImageView
myImage.setImageBitmap(bm)//set the ImageView bitmap
+0
好的,但是如何从服务器下载/读取ByteArray? – Christer
0
,我发现我的解决方案,这里是代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// show The Image
new DownloadImageTask((ImageView) findViewById(R.id.imageView1))
.execute("http://myURL");
}
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
相关问题
- 1. 如何将bytearray转换为图像或图像bytearray?
- 2. 如何将byteArray转换为位图图像以在Android中的imageview中显示?
- 3. 转换PIL图像为bytearray
- 4. AJAX将图像转换为ByteArray
- 5. PIL:将Bytearray转换为图像
- 6. 将byteArray转换为android中的位图?
- 7. 如何将bytearray转换为zip文件
- 8. 将ByteArray转换为文件对象
- 9. 将图像信息从服务器转换为json
- 10. 将图像转换服务器端CanvasPixelArray
- 11. 服务器端将光栅图像转换为矢量图像
- 12. 将图像转换为从服务器加载的9补丁图像
- 13. Flex处理图像(转换为Bytearray)
- 14. 如何将图像转换为Flex 4中的ByteArray
- 15. 将图标转换为Web服务器C上的PNG文件#
- 16. 无法转换图像位图的ByteArray
- 17. 将位图转换为byteArray android
- 18. 将ByteArray转换为NSData
- 19. 将BinaryString转换为ByteArray - Java
- 20. 将负值转换为bytearray
- 21. 将System.Windows.Media.ImageSource转换为ByteArray
- 22. .net将bytearray转换为double []
- 23. 将bytearray转换为整数
- 24. 将MovieClip转换为ByteArray
- 25. 如何将画布转换为服务器上的图像
- 26. 将图像转换为服务器端的视频由php
- 27. 将图像从服务器下载到imageview时的性能
- 28. 是否可以保存从服务器下载的mp3文件,而无需将其转换为ByteArray? (AS3)
- 29. 如何将图像转换为android中的文本转换器?
- 30. 将服务器文件路径转换为Codeigniter中的URL
您的字节组转换为位图,然后设置'ImageView'的位图。 'Bitmap bm = BitmapFactory.decodeByteArray(myByteArray,0,byteArray.length);' – john
而不是将“解决”添加到主题行,请接受您的答案以表明您的问题已经解决。 –
我必须等待几个小时才能接受我的答案:) – Christer