android加载网络图片有一个bug,至少目前我在android1.5.jar中没有找到解决方案。

昨天关于jpg、gif和png的帖子已经提到,png是支持interlaced的。j2me、symbian、wm和iphone在网络加载interlaced格式的png时没有出现问题,但是android在网络加载interlaced格式的png时就会出现图像模糊不清的现象(根据interlaced原理,再经过观察,我估计是只扫描了奇数行而没有扫描偶数行,所以出现了图像模糊的状况)。

android网络加载图片的方式有两种:(1)用HttpURLConnection取得InputStream,再用InputStream流作为参数,利用android提供的api生成图片。(2)用HttpClick(apche的一个开源项目,被引用到android中了),取得图片流的byte[]信息,然后以byte[]作为参数生成图片。前文已有论述,遂不赘述。现只将实际图片贴上来以说明这个bug,希望做android底层开发的兄弟姐妹们能尽快帮忙修复这个bug。

1. interlaced格式图片

2. none interlaced格式图片

Bug-Report: Interlaced PNG bitmap acquired through network is blurred
I was trying to acquire interlaced PNG bitmap through network, there is no warn or errer in resulting output, but this interlaced PNG bitmap acquired from network is blurred, very blurred.
If the interlaced PNG is acquired from native(res/drawable), it is distinct;
If the PNG bitmap is not interlaced, load it from either network or native, it is distinct.
I think the reason is: android just scan odd-numbered or even-numbered rows of the interlaced PNG, but doesn't scan scan even-numbered or odd-numbered rows of the interlaced PNG

Main Codes:

public void surfaceCreated(SurfaceHolder holder) {canvas = mHolder.lockCanvas();  Paint mPaint = new Paint();  try {String strURL = "http://www.tiexin.com/images/map_blocks/1/4/3/3/00000037_00000031.png";canvas.drawBitmap(getBitmap(strURL), 0, 0, mPaint);} catch (IOException e) {e.printStackTrace();}}     private Bitmap getBitmap(String strURL) throws IOException {URL url = new URL(strURL);HttpURLConnection conn = (HttpURLConnection) url.openConnection();conn.setDoInput(true);conn.setConnectTimeout(1000);conn.setRequestMethod("GET");conn.connect();for (int i = 0; i < 5; i++) { // 连接5次if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {InputStream is = conn.getInputStream();Bitmap bm = BitmapFactory.decodeStream(is, null, null);if (is != null) {is.close();is = null;}if (conn != null) {conn.disconnect();conn = null;}return bm;}}return null;}

Welcome to visit my blog to see the effect drawing
http://wayfarer.iteye.com/admin/blogs/442586

更多相关文章

  1. [转] Android TextView处理HTML标签、显示图片等
  2. Android之 RecyclerView,CardView 详解和相对应的上拉刷新下拉加
  3. 2014-11-8Android学习------Android 实现图片的旋转--------动画
  4. android中使用线程池和临时缓存优化网络图片加载
  5. Android Nine Patch图片及按钮背景
  6. Android通过加载其他应用的Dex文件破解关键数据
  7. Android图片异步加载之Android-Universal-Image-Loader

随机推荐

  1. Android View - 实现流式布局
  2. Android-ANR-Android App优化之ANR详解
  3. Android开发之如何读写文件
  4. ListView可复用适配器的封装及性能优化
  5. commons.dbutils1.2介绍及使用
  6. DJI SDK开发——第一个程序
  7. Android---Volley请求天气接口JSON解析
  8. 获取上周五的日期,除非今天是星期五使用T-
  9. 提供一个Android原生的Progress——Swipe
  10. Mysql替代解决方案Cassandra