从手机相册里面显示图片,但是发现有的图片能显示有的图片不能显示,路径都是对的,程序也没提示任何错误。
后来通过看日志发现error message: Bitmap too large to be uploaded into a texture (4208x3120, max=4096x4096):
Bitmap too large to be uploaded into a texture
 
经过查找资料是因为当开启硬件加速的时候,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;

    }

  

相关文章:

  • 2021-09-17
  • 2021-07-20
  • 2021-09-30
  • 2022-12-23
  • 2021-06-07
  • 2021-09-13
  • 2021-08-08
  • 2021-09-02
猜你喜欢
  • 2022-01-28
  • 2021-09-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
相关资源
相似解决方案