android加载网络图片(逐行扫描格式png图片)的一个bug

Android加载交错PNG图片模糊
在Android设备上加载网络中的交错格式PNG图片时会出现模糊现象。该问题在使用其他平台时未出现,疑似Android仅扫描了图片的部分行。本文提供了一个示例代码,用于展示如何加载这些图片。

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

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值