首页 > 笔记 > 正文

Bitmap too large to be uploaded into a texture

2016-04-07 笔记 2976 ℃ 0 评论
从手机相册里面显示图片,但是发现有的图片能显示有的图片不能显示,路径都是对的,程序也没提示任何错误。
后来通过看日志发现error message: Bitmap too large to be uploaded into a texture (4208x3120, max=4096x4096):
经过查找资料是因为当开启硬件加速的时候,GPU对于openglRender 有一个限制,这个不同的手机会有不同的限制。
简单说就是硬件加速的时候,对图片的大小有限制。不同设备可能有不同的最大值。这个问题悲催的地方是,程序貌似没有捕获到这个exception, 结果是程序也不报错,图片也显示不出来。
 
一个解决的方法是禁止硬件加速 
 <application android:hardwareAccelerated="false" ...>
/**
 * 把uri 转换为 bitmap          注意要关闭硬件加速!!否则会因为图片超大而不显示
 * @param mContext
 * @param mUri
 * @return
 */
public static  Bitmap readBitmapUri(Context mContext,Uri mUri) {
    ContentResolver contentProvider = mContext.getContentResolver();
    Bitmap bmp = null;
    try {
        bmp = BitmapFactory.decodeStream(contentProvider.openInputStream(mUri));
 
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return bmp;
 
}


猜你喜欢

日历
«    2024年3月    »
123
45678910
11121314151617
18192021222324
25262728293031
标签列表
最近发表
友情链接