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(安卓)人脸识别+人脸匹配(OpenCV+JavaCV)
  2. android: 静态XML和动态加载XML混合使用,以及重写Layout控件
  3. android——再谈加载大量图片性能问题
  4. Android(安卓)9 网络适配 (系统造成App内图片无法加载解决方案)
  5. Android中Image的简单实例详解
  6. Android高手进阶教程(二十二)之Android中几种图像特效处理的集锦
  7. [置顶] 修改Android开机画面之rle制作
  8. Android(安卓)选择图片、上传图片之PictureSelector
  9. [Android] 使用Matrix矩阵类对图像进行缩放、旋转、对比度、亮度

随机推荐

  1. Android中的矢量动画
  2. Linux下Android SDK环境搭建--使用命令更
  3. Android探索之旅 | AIDL原理和实例讲解
  4. android消除锯齿原理分析
  5. Android三种播放视频的方式
  6. Android(安卓)native CursorWindow数据保
  7. Mac AndroidStudio真机调试
  8. 关于单选框RadioGroup和RadioButton
  9. Android引路蜂地图开发示例:第一个地图应
  10. android手机图片查看