Bitmap too large to be uploaded into a texture问题的解决方法

来源:互联网 发布:广东电信网络传真 编辑:程序博客网 时间:2024/05/29 10:59

当加载的图片过大时,通常采用的方法是直接按照图片的比例压缩图片,显示出来

避免因为图片的过大而造成Oout of Menmery,具体方法这里看

http://blog.csdn.net/siyehuazhilian/article/details/16965689


但是当图片的宽高比例差距非常大的时候,即长图.

用上述的方法会造成短的一边的像素严重丢失以至于模糊不清

可以在ImageView的属性中设置:

android:maxHeight="1000dip"android:maxWidth="1000dip"

在图片过大的时候ImagLoder会自动处理图片避免OOM

但是仅仅这样,图片有可能会显示不出来,看Log日志:

 Bitmap too large to be uploaded into a texture的意思是图片超过了硬件加速所规定的高度

这个时候我们只需要禁止硬件加速即可

android:hardwareAccelerated="false"

事实上,这是一个简单有效的方法

但是这个方法最好在这个Activity比较少用到的时候使用,因为禁止硬件加速总归不是什么好事

还有一个方法是:

重写ImagView的下列两个方法,可以分步显示长图

http://developer.android.com/reference/android/graphics/BitmapRegionDecoder.html

1public void drawBitmap (Bitmap bitmap, Rect src, RectF dst, Paint paint)
2 
3public Bitmap decodeRegion (Rect rect, BitmapFactory.Options options)

1 0
原创粉丝点击