Bitmap too larget to be uploaded into a texture的解决方法

问题描述

使用canvas.drawBitmap()系列方法时,抛出错误Bitmap too larget to be uploaded into a texture。

问题原因

错误日志的内容是

W/OpenGLRenderer: Bitmap too large to be uploaded into a texture (1204x4533, max=4096x4096)

所以,可以得知问题的原因是设置src的图片宽高大于了最大接受的值,所以抛出错误。

本来想换着想法实现,经过测试发现设置background,src都会有这样的问题出现。

解决方法

使用BitmapFactory.decodeStream()系列方法将图片的宽高进行压缩。

	if (bitmap != null) {
int maxWidth = canvas.getMaximumBitmapWidth();
int maxHeight = canvas.getMaximumBitmapHeight();
int width = bitmap.getWidth();
int height = bitmap.getHeight();
if (width > maxWidth || height > maxHeight) {
int inSampleSize;
int heightRatio = Math.round((float) height / (float) maxHeight);
int widthRatio = Math.round((float) width / (float) maxWidth);
inSampleSize = heightRatio < widthRatio ? widthRatio : heightRatio;
if (inSampleSize == 1) {
inSampleSize = 2;
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray());
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = inSampleSize;
options.inJustDecodeBounds = false;
bitmap = BitmapFactory.decodeStream(isBm, null, options);
}
}

将上面这段代码添加到合适的位置,问题就解决了。

参考文章

https://blog.csdn.net/vickywinner/article/details/53164702

Bitmap too larget to be uploaded into a texture的解决方法的更多相关文章

  1. fresco Bitmap too large to be uploaded into a texture

    fresco加载图片方法 布局文件引入 xmlns:fresco="http://schemas.android.com/apk/res-auto" <com.faceboo ...

  2. 解决:Bitmap too large to be uploaded into a texture exception

    前几天拿锤子手机做测试,启动页面的闪屏直接黑屏.. 所以看下日志,百度一下 找到解决方案,特此记录. 简单说就是硬件加速的时候,对图片的大小有限制.不同设备可能有不同的最大值.这个问题悲催的地方是,程 ...

  3. imageview设置图片时超长超大图片超出限制(OpenGLRenderer: Bitmap too large to be uploaded into a texture (996x9116, max=4096x4096))

    问题:遇到超长图片,宽长等比缩放,比如宽度同屏幕同宽,长度等比放大,放到后遇到长度超出OpenGLRenderer的最大限制,导致图片无法显示出来: 解决办法: //图片超出GPU对于openglRe ...

  4. java.lang.OutOfMemoryError: bitmap size exceeds VM budget解决方法

    1 BitmapFactory.decodeFile(imageFile); 用BitmapFactory解码一张图片时,有时会遇到该错误.这往往是由于图片过大造成的.要想正常使用,则需要分配更少的内 ...

  5. Android中View转换为Bitmap及getDrawingCache=null的解决方法

    1.前言 Android中经常会遇到把View转换为Bitmap的情形,比如,对整个屏幕视图进行截屏并生成图片:Coverflow中需要把一页一 页的view转换为Bitmap.以便实现复杂的图形效果 ...

  6. 关于BitmapFactory.decodeStream(is)方法无法正常解码为Bitmap对象的解决方法

    在android sdk 1.6版本API帮助文档中,其中关于BitmapFactory.decodeFactory.decodeStream(InputStream is)的帮助文档是这么说明的: ...

  7. [Android Pro] 关于BitmapFactory.decodeStream(is)方法无法正常解码为Bitmap对象的解决方法

    在android sdk 1.6版本API帮助文档中,其中关于BitmapFactory.decodeFactory.decodeStream(InputStream is)的帮助文档是这么说明的: ...

  8. Android Bitmap太大导致ImageView不显示的问题

    今天做我们的智能相冊的项目时,遇到了非常奇妙的问题,当照片太大时,导致ImageView.setImageBitmap不显示,上网上搜了非常多办法.感觉都不是那么靠谱.最后使用了简单粗暴的手段: // ...

  9. bug1

    1从相册中获取图片,低版本可以,高版本不行.看见抛出 Bitmap too large to be uploaded into a texture 原来是高版本的android,机子好点,相机就好点, ...

随机推荐

  1. Python开发——目录

    Python基础 Python开发——解释器安装 Python开发——基础 Python开发——变量 Python开发——[选择]语句 Python开发——[循环]语句 Python开发——数据类型[ ...

  2. Linux关闭防火墙命令

    下面是red hat/CentOs7关闭防火墙的命令! 1:查看防火状态 systemctl status firewalld service  iptables status 2:暂时关闭防火墙 s ...

  3. 解决js数组循环删除出错

    for(var i=0,flag=true,len=arr.length;i<len;flag ? i++ : i){ if( arr[i]&&arr[i].status==0 ...

  4. OO第二单元单元总结

    总述 OO的第二单元主题是电梯调度,与第一单元注重对数据的输入输出的处理.性能的优化不同,第二单元的重心更多的是在线程安全与线程通信上.这此次单元实验之前,我并未对线程有过了解,更谈不上“使用经验”, ...

  5. java的多态性

    class test1{    int a=3;    public test1(int a)    {        this.a=a;    }    public void aa()    {  ...

  6. ----XMLHttpRequestAPI简单介绍----

    XMLHttpRequest 使用XMLHttpRequest (XHR)对象可以与服务器交互.您可以从URL获取数据,而无需让整个的页面刷新.这使得Web页面可以只更新页面的局部,而不影响用户的操作 ...

  7. WebApi 增加身份验证 (OAuth 2.0方式)

    1,在Webapi项目下添加如下引用: Microsoft.AspNet.WebApi.Owin Owin Microsoft.Owin.Host.SystemWeb Microsoft.Owin.S ...

  8. C#学习笔记14——TRACE、DEBUG和TRACESOURCE的使用以及日志设计

    Trace.Debug和TraceSource的使用以及日志设计   .NET Framework 命名空间 System.Diagnostics 包含用于跟踪执行流程的 Trace.Debug 和 ...

  9. 使用rancher2建k8s集群--个人学习记录

    视频地址这里: http://live.vhall.com/431874021 原生文档这里:https://www.cnrancher.com/docs/rancher/v2.x/cn/overvi ...

  10. c#串口测试

    软件和代码网盘下载 https://pan.baidu.com/s/1dFrE1pv#list/path=%2F SerialPort 类 https://msdn.microsoft.com/zh- ...