在某些三星机子里使用
Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
当width=(屏幕宽度)height=屏幕高度时,容易出现oom,可以使用:
http://zhidao.baidu.com/link?url=YzCmJlXyVVmr1GHnXqsLmn9BpwoRfNefDdxNbr_tBzjXQDyL7W962T5eJh8yvGwxNo8YunYvQO6ScdT2c7urjK
http://wenku.baidu.com/view/c7b20053ad02de80d4d840f9.html
BitmapFactory.Options bfOptions=new BitmapFactory.Options();
bfOptions.inDither=false;//使图片不抖动。不是很懂
bfOptions.inPurgeable=true;//使得内存可以被回收
bfOptions.inTempStorage=new byte[12 * 1024]; //临时存储
File file = new File(path);//path:图片的绝对地址
FileInputStream fs=null;
try {
fs = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Bitmap bmp = null;
if(fs != null) {
try {
bmp = BitmapFactory.decodeFileDescriptor(fs.getFD(), null, bfOptions); //这样莫非就让bmp到了临时存储的位置?
} catch (IOException e) {
e.printStackTrace();
}finally{
if(fs!=null) {
try {
fs.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
也可以使用Bitmap.createBitmap(width,
height,Bitmap.Config.RGB_565); 16bit,比reg_8888节约一半的内存容量
今天使用:
org.apache.commons
出现:
This works because even though Android does not have encodeHexString(), it does have encodeHex(). Hope this would
help others who run into the same issue.
可以看看:http://stackoverflow.com/questions/9126567/method-not-found-using-digestutils-in-android
解决方案,出错原因:
http://blog.youkuaiyun.com/luoqintao/article/details/12019263
根本原因应该是android内部库也有一个org.apache.commons.codecs.*的
jar,导致包名冲突,而优先加载了系统的,而系统的jar包中却没有encodeHexString():
本文探讨了在Android应用中优化内存使用的方法,包括使用特定的Bitmap创建方式来避免内存溢出,以及遇到编码问题时的解决策略。通过实例展示了如何使用BitmapFactory.Options进行配置以减少内存消耗,并提供了相关链接以深入理解这些问题和解决方案。

被折叠的 条评论
为什么被折叠?



