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. 微信x5内核很鸡贼啊

    最近在写一个支付项目,然后要打通微信和支付宝支付,本来后端联调的时候直接调用weixin://wxpay/bizpayurl?XXXX接口就行的,完全走着通,然后到项目验收了就炸了,点不进去了,最后改 ...

  2. 使用DOS命令无法启动MySQL

    今天使用命令dos 命令 net start mysql 启动mysql的使用出现以下情况 无法正常启动mysql服务. 原因是: 启动dos命令窗口时的用户权限太低,无法正常使用 解决办法: 搜索c ...

  3. 设计模式学习心得<原型模式 Prototype >

    原型模式(Prototype Pattern)是用于创建重复的对象,同时又能保证性能.这种类型的设计模式属于创建型模式,它提供了一种创建对象的最佳方式. 这种模式是实现了一个原型接口,该接口用于创建当 ...

  4. 腾讯开源项目phxpaxos的编译步骤

    #paxos的一般编译流程在项目文档<中文详细编译手册>里面已经有介绍,这里重点介绍一下编译samples目录下的代码: #我的环境是ubuntu; #设置paxos根目录 phx_dir ...

  5. HttpWebRequest 自定义header,Post发送请求,请求形式是json,坑爹的代码

    public static string PostMoths(string url, LoginDTO obj_model, Dictionary<string, string> dic ...

  6. mysql安装完启动问题解决

    一.初始化报错问题: 1./usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/loca ...

  7. C# 互通操作 (二)基础知识1

    [DllImport("user32.dll", EntryPoint = "MessageBox")] public static extern int De ...

  8. WARN [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:QuorumCnxManager@584] - Cannot open channel to 4 at election address Slave3.Hadoop/xxx.xxx.xxx.xxx

    这些日子为这个错误苦恼很久了,网上找到的各种方法都试了一遍,还是没能解决. 安装好zookeeper后,运行zkServer.sh start 显示正常启动,但运行zkServer.sh status ...

  9. media 标签解释

    一:常用标签这句话是自动设置缩放,然而,它并不能完全适应所有的手机,并且你在用浏览器手机模式调试的时候可能正常,但是换到真实的手机端其实是不正常的.所以我们还要进行改动. <meta name= ...

  10. post文件下载

    this.$http({ method: 'post', url: '/file/download', responseType: 'blob', data: JSON.stringify(this. ...