【Android开发经验】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;
} }
【Android开发经验】Cannot generate texture from bitmap异常的解决方式的更多相关文章
- 连接db2数据库时NumberFormatException异常的解决方式
连接db2数据库时报异常:java.lang.NumberFormatException: For input string: "A" from a DB2 JDBC(JCC) j ...
- Hadoop常见异常及其解决方式
1.Shell$ExitCodeException 现象:执行hadoop job时出现例如以下异常: 14/07/09 14:42:50 INFO mapreduce.Job: Task Id : ...
- android EditText 限定中文个数与英文个数的解决方式
EditText 限定中文8个英文16个的解决方法. 在EditText上控件提供的属性中有限定最大最小长度的方法. 可是,对于输入时,限定中文8个英文16个时,怎么办?相当于一个中文的长度是两个英文 ...
- dubbo常见异常及解决方式
1.出现RpcException: Failed to invoke the method post in the service com.xxx.xxx.xxx异常怎么办?表示调用失败1.检查网络是 ...
- celery出现警告或异常的解决方式
做个笔记,记录下使用celery踩过的坑,不定期更新. warnings.warn(CDeprecationWarning(W_PICKLE_DEPRECATED)) 我用的是Flask,所以在Fl ...
- Android Studio 错误: 非法字符: '\ufeff' 解决方式|错误: 须要class, interface或enum
在导入eclipse项目到Android Studio出现这种错误, 非法字符: '\ufeff' 解决方式|错误: 须要class, interface或enum.查阅后了解到Eclipse能够智能 ...
- android通过BitmapFactory.decodeFile获取图片bitmap报内存溢出的解决办法
android通过BitmapFactory.decodeFile获取图片bitmap报内存溢出的解决办法 原方法: public static Bitmap getSmallBitmap(Strin ...
- 【我的Android进阶之旅】 RxJava 理解Backpressure并解决异常 rx.exceptions.MissingBackpressureException
今天测试人员在测试应用APP的时候应用crash了,查看了下crash log如下所示: java.lang.IllegalStateException: Exception thrown on Sc ...
- Android开发之高效加载Bitmap
一.概述 在Android开发中,我们经常与Bitmap打交道,而对Bitmap的不恰当的操作经常会导致OOM(Out of Memory).这篇文章我们会介绍如何高效地在Android开发中使用Bi ...
随机推荐
- 33.NET对加密和解密的支持
散列运算 mscorlib.dll下的System.Security.Cryptography下: 抽象类HashAlgorithm 抽象类MD5 MD5CryptoSer ...
- mysql 主从复制原理(转)
本文转自https://blog.csdn.net/php_younger/article/details/59673879 mysql 主从复制原理 主从形式 mysql主从复制 灵活 一主一从 ...
- xml转换成map
import java.io.IOException;import java.io.StringReader;import java.util.ArrayList;import java.util.H ...
- Spring+Quartz 集群
这几天给Spring+Quartz的集群折腾得死去活来,google了无数页总算搞定,记下一些要点备以后使用. 单独的Quartz集群在http://unmi.blogjava.net/有Unmi翻译 ...
- django的单元测试框架unittest、覆盖率
django的单元测试 指定测试范围: 指定运行某些测试文件./manage.py test --pattern="tests_*.py" -v 2 运行所有测试文件./manag ...
- C++ Explicit Constructors(显式构造函数)
C++ 为类(Class)提供了许多默认函数.如果自己没有申明,编译器会为我们提供一个copy构造函数.一个copy assignment操作符和一个析构函数.此外,如果没有申明任何构造函数,编译器会 ...
- 80端口占用异常解决方法java.net.BindException: Address already in use: JVM_Bind:80(或8080)
1:Tomcat(或其他Web容器)启动时控制台报错如下示: 2007-8-2 15:20:43 org.apache.coyote.http11.Http11Protocol init 严重: Er ...
- LA 4728 Square ,旋转卡壳法求多边形的直径
给出一些正方形.让你求这些正方形顶点之间的最大距离的平方. //返回点集直径的平方 int diameter2(vector<Point> & points) { vector&l ...
- GO语言基础之struct
结构struct 1. Go 中的struct与C中的struct非常相似,并且Go没有class 2. 使用 type <Name> struct{} 定义结构,名称遵循可见性规则(即首 ...
- Leaf - 一个由 Go 语言编写的开发效率和执行效率并重的开源游戏服务器框架
转自:https://toutiao.io/posts/0l7l7n/preview Leaf 游戏服务器框架简介 Leaf 是一个由 Go 语言(golang)编写的开发效率和执行效率并重的开源游戏 ...