Bitmap 图片异步加载
来源:互联网 发布:淘宝买托福答案被骗 编辑:程序博客网 时间:2024/05/22 08:15
package com.example.zhangjinling0901;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.HttpURLConnection;
import java.net.URL;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Handler;
import android.os.Message;
import android.widget.ImageView;
import android.graphics.BitmapFactory;
import android.os.Handler;
import android.os.Message;
import android.widget.ImageView;
public class ImageUtil {
ImageView imageView;
ImageView imageView;
private Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
if (msg.what == 0){
Bitmap bitmap = (Bitmap) msg.obj;
imageView.setImageBitmap(bitmap);
}
}
};
@Override
public void handleMessage(Message msg) {
if (msg.what == 0){
Bitmap bitmap = (Bitmap) msg.obj;
imageView.setImageBitmap(bitmap);
}
}
};
/**
* 给imageView控件加载图片
*/
public void getImage(final String path, ImageView imageView){
this.imageView = imageView;
* 给imageView控件加载图片
*/
public void getImage(final String path, ImageView imageView){
this.imageView = imageView;
new Thread(){
@Override
public void run() {
try {
URL url = new URL(path);
@Override
public void run() {
try {
URL url = new URL(path);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setReadTimeout(5000);
connection.setConnectTimeout(5000);
connection.setReadTimeout(5000);
connection.setConnectTimeout(5000);
//响应的状态码
int responseCode = connection.getResponseCode();
if (responseCode == 200){
InputStream inputStream = connection.getInputStream();
int responseCode = connection.getResponseCode();
if (responseCode == 200){
InputStream inputStream = connection.getInputStream();
//转为bitmap
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
//向Handler发送数据
Message message = Message.obtain();
message.what = 0;
message.obj = bitmap;
handler.sendMessage(message);
}
message.what = 0;
message.obj = bitmap;
handler.sendMessage(message);
}
} catch (Exception e) {
e.printStackTrace();
}
e.printStackTrace();
}
}
}.start();
}.start();
}
}
}
阅读全文
0 0
- 异步加载bitmap图片
- Bitmap 图片异步加载
- Bitmap异步加载网络图片
- Bitmap高效加载图片
- Bitmap 高效加载图片
- Bitmap 的图片加载
- android: 缓存异步加载Bitmap
- 异步获取网络图片Bitmap
- BitMap高效显示策略(二):在ListView上异步加载网络图片
- Bitmap二次采样,Android中的缓存处理及异步加载图片类的封装
- Bitmap的二次采样,异步加载网络图片到控件上
- Bitmap如何高效加载图片
- 异步加载图片
- 异步加载图片
- ajax异步加载图片
- android异步加载图片
- 异步图片加载实例
- android 异步加载图片
- vue-cli项目中怎么mock数据
- MySQL中根据某一列列值进行排名的方法
- 基于docker的微服务容器化与编排
- stm32常见通信方式(TTL、RS232、RS485、CAN)总结
- 多继承的二义性和虚继承(虚基类)
- Bitmap 图片异步加载
- leetcode No198. House Robber
- codeblock快捷键设置
- DownloadManager 文件下载
- Glide--Android图片缓存
- Android数据存储之Sqlite的介绍及使用
- 编码规范
- promise 和async await
- 数据结构思维 第六章 树的遍历