Ami*_*mit 1 android bitmap android-imageview android-asynctask
我正在尝试使用异步请求从URL中获取图像,以防止URL挂起.这是我正在使用的代码片段
private void setImg(final ImageView im, String url){
AsyncHttpClient client = new AsyncHttpClient();
client.get(url, new AsyncHttpResponseHandler(){
public void onSuccess(String response){
try{
byte[] imageAsBytes = response.getBytes();
im.setImageBitmap(BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length));
im.refreshDrawableState();
} catch(Throwable e){
e.printStackTrace();
}
}
});
}
Run Code Online (Sandbox Code Playgroud)
这总是在logcat中显示此警告
12-29 01:55:33.043: D/skia(14414): --- SkImageDecoder::Factory returned null
我找不到合适的理由.有帮助吗?
现在已经将一个二进制响应处理程序添加到AsyncHttp中,您只需使用androids BitmapFactory.decodeByeArray函数:
AsyncHttpClient client = new AsyncHttpClient();
client.get(image_url, null, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(byte[] fileData) {
Bitmap image = BitmapFactory.decodeByteArray(fileData, 0, fileData.length);
//Do whatever you want with the image variable
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6680 次 |
| 最近记录: |