设为首页 加入收藏

TOP

Cannot generate texture from bitmap异常的解决方案
2015-07-20 17:30:30 来源: 作者: 【 】 浏览:3
Tags:Cannot generate texture from bitmap 异常 解决方案

异常现象:

今天在处理用户头像的过程中,由于头像的处理比较复杂,因为,没有使用afinal自带的自动加载,而是自己根据头像的下载路径,手动进行下载和使用。但是在手动回收bitmap对象的过程中,会出现Cannot generate texture from bitmap异常的情况,同时,ImageView显示是黑色的,图像不能正常显示。


解决方案:

在查阅了一些其他人的资料之后,发现这可能是由于4.0之后系统开启了GPU硬件加速导致的,因此,我们可以在图片加载之前,设置ImageView为关闭硬件加速状态,因此,我们可以用下面的代码完成。

if (SystemUtils.getSystemVersion() >= SystemUtils.V4_0) {
			img_header.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
		}


之所以要加上版本控制,是因为设置图片的非硬件加速模式是在api11之后添加的,因此,我们需要进行版本的控制,否则,在低版本上运行会报错。

下面是检测版本的帮助类SystemUtils.java

/**
 * 
 * @ClassName: com.drd.piaojubao.utils.SystemUtils
 * @Description: 当前平台系统的工具类
 * @author zhaokaiqiang
 * @date 2014-10-11 上午9:51:47
 * 
 */
public class SystemUtils {

	public static final int V2_2 = 8;
	public static final int V2_3 = 9;
	public static final int V2_3_3 = 10;
	public static final int V3_0 = 11;
	public static final int V3_1 = 12;
	public static final int V3_2 = 13;
	public static final int V4_0 = 14;
	public static final int V4_0_3 = 15;
	public static final int V4_1 = 16;
	public static final int V4_2 = 17;
	public static final int V4_3 = 18;
	public static final int V4_4 = 19;

	/**
	 * 
	 * @Description: 检测当前的版本信息
	 * @param
	 * @return int
	 * @throws
	 */
	public static int getSystemVersion() {
		return android.os.Build.VERSION.SDK_INT;
	}

}



】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Launcher知识的demo,手机管家小.. 下一篇IE 8兼容:X-UA-Compatible的解释

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Linux_百度百科 (2025-12-26 12:51:52)
·Shell 流程控制 | 菜 (2025-12-26 12:51:49)
·TCP/UDP协议_百度百科 (2025-12-26 12:20:11)
·什么是TCP和UDP协议 (2025-12-26 12:20:09)
·TCP和UDP详解 (非常 (2025-12-26 12:20:06)