java异步上传图片示例
时间:2023-05-31 13:42:51
final File imageFile = new File(getCacheDir().getPath() + "/img/" + p.image);
image.setVisibility(View.GONE);
view.findViewById(R.id.imageLoading).setVisibility(View.VISIBLE);
(new AsyncTask<Void, Void, Bitmap>() {
@Override
protected Bitmap doInBackground(Void... params) {
try {
Bitmap image;
if (!imageFile.exists() || imageFile.length() == 0) {
image = BitmapFactory.decodeStream(new URL(
"http://example.com/images/"
+ p.image).openStream());
image.compress(Bitmap.CompressFormat.JPEG, 85,
new FileOutputStream(imageFile));
image.recycle();
}
image = BitmapFactory.decodeFile(imageFile.getPath(),
bitmapOptions);
return image;
} catch (MalformedURLException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
return null;
} catch (IOException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
return null;
}
}
@Override
protected void onPostExecute(Bitmap image) {
if (view.getTag() != p) // The view was recycled.
return;
view.findViewById(R.id.imageLoading).setVisibility(
View.GONE);
view.findViewById(R.id.image)
.setVisibility(View.VISIBLE);
((ImageView) view.findViewById(R.id.image))
.setImageBitmap(image);
}
}).execute();
标签:java,异步上传,图片
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java实现按权重随机数
2023-11-28 23:15:32
Java 自定义注解的魅力
2023-06-29 14:45:15
![](https://img.aspxhome.com/file/2023/6/65776_0s.png)
Java处理InterruptedException异常的理论与实践
2023-07-25 03:22:33
Android TextView字幕效果实例
2022-03-18 14:55:13
![](https://img.aspxhome.com/file/2023/1/97841_0s.png)
c++异常处理机制示例及详细讲解
2022-04-27 11:31:27
SSH原理及两种登录方法图文详解
2023-11-14 11:10:53
![](https://img.aspxhome.com/file/2023/8/59038_0s.png)
HDFS Balancer负载均衡器及语法详解
2023-11-18 18:30:39
![](https://img.aspxhome.com/file/2023/9/131899_0s.png)
C#中遍历Hashtable的4种方法
2023-01-18 12:17:51
![](https://img.aspxhome.com/file/2023/8/125898_0s.png)
Java全面分析面向对象之继承
2023-11-23 11:55:59
![](https://img.aspxhome.com/file/2023/5/59735_0s.png)
关于@Scheduled不执行的原因分析
2021-06-27 17:13:20
![](https://img.aspxhome.com/file/2023/9/67619_0s.png)
详解android 用webview加载网页(https和http)
2021-12-29 11:14:30
slf4j jcl jul log4j1 log4j2 logback各组件系统日志切换
2023-08-08 13:00:41
![](https://img.aspxhome.com/file/2023/8/57928_0s.png)
springboot接收别人上传的本地视频实例代码
2023-03-22 01:55:39
Java Idea TranslationPlugin翻译插件使用解析
2023-12-01 10:25:02
![](https://img.aspxhome.com/file/2023/4/66204_0s.png)
C++多重继承与虚继承分析
2023-04-22 14:49:16
![](https://img.aspxhome.com/file/2023/8/117788_0s.png)
Spring Security 实现用户名密码登录流程源码详解
2023-05-31 11:13:59
![](https://img.aspxhome.com/file/2023/8/64058_0s.png)
SpringCloud使用Zookeeper作为配置中心的示例
2023-08-03 12:30:51
![](https://img.aspxhome.com/file/2023/6/132176_0s.jpg)
android实现okHttp的get和post请求的简单封装与使用
2023-10-06 04:20:25
Android 破解视频App去除广告功能详解及解决办法总结
2022-07-16 23:28:50
![](https://img.aspxhome.com/file/2023/8/108288_0s.png)
JavaWeb项目部署到服务器详细步骤详解
2023-11-29 11:15:20
![](https://img.aspxhome.com/file/2023/4/58764_0s.png)