Bitmap too larget to be uploaded into a texture的解决方法
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的解决方法的更多相关文章
- fresco Bitmap too large to be uploaded into a texture
fresco加载图片方法 布局文件引入 xmlns:fresco="http://schemas.android.com/apk/res-auto" <com.faceboo ...
- 解决:Bitmap too large to be uploaded into a texture exception
前几天拿锤子手机做测试,启动页面的闪屏直接黑屏.. 所以看下日志,百度一下 找到解决方案,特此记录. 简单说就是硬件加速的时候,对图片的大小有限制.不同设备可能有不同的最大值.这个问题悲催的地方是,程 ...
- imageview设置图片时超长超大图片超出限制(OpenGLRenderer: Bitmap too large to be uploaded into a texture (996x9116, max=4096x4096))
问题:遇到超长图片,宽长等比缩放,比如宽度同屏幕同宽,长度等比放大,放到后遇到长度超出OpenGLRenderer的最大限制,导致图片无法显示出来: 解决办法: //图片超出GPU对于openglRe ...
- java.lang.OutOfMemoryError: bitmap size exceeds VM budget解决方法
1 BitmapFactory.decodeFile(imageFile); 用BitmapFactory解码一张图片时,有时会遇到该错误.这往往是由于图片过大造成的.要想正常使用,则需要分配更少的内 ...
- Android中View转换为Bitmap及getDrawingCache=null的解决方法
1.前言 Android中经常会遇到把View转换为Bitmap的情形,比如,对整个屏幕视图进行截屏并生成图片:Coverflow中需要把一页一 页的view转换为Bitmap.以便实现复杂的图形效果 ...
- 关于BitmapFactory.decodeStream(is)方法无法正常解码为Bitmap对象的解决方法
在android sdk 1.6版本API帮助文档中,其中关于BitmapFactory.decodeFactory.decodeStream(InputStream is)的帮助文档是这么说明的: ...
- [Android Pro] 关于BitmapFactory.decodeStream(is)方法无法正常解码为Bitmap对象的解决方法
在android sdk 1.6版本API帮助文档中,其中关于BitmapFactory.decodeFactory.decodeStream(InputStream is)的帮助文档是这么说明的: ...
- Android Bitmap太大导致ImageView不显示的问题
今天做我们的智能相冊的项目时,遇到了非常奇妙的问题,当照片太大时,导致ImageView.setImageBitmap不显示,上网上搜了非常多办法.感觉都不是那么靠谱.最后使用了简单粗暴的手段: // ...
- bug1
1从相册中获取图片,低版本可以,高版本不行.看见抛出 Bitmap too large to be uploaded into a texture 原来是高版本的android,机子好点,相机就好点, ...
随机推荐
- windows下的mongodb安装与配置
一.下载mongodb安装文件 https://www.mongodb.com/download-center/community 选择zip压缩包方式,如:mongodb-win32-x86_64- ...
- 谷歌搜索技巧(转)https://www.runningcheese.com/google
原文地址: Google是一个非常精密成熟的搜索引擎,其搜索结果的丰富性和准确度较其他搜索引擎都要好,但大多数用户都还只是停留在搜索框中输入一两个关键字,然后点击“搜索”按钮的阶段,这一过程是非常低效 ...
- Redis数据类型-Strings
Redis 简介 REmote DIctionary Server(Redis) 是一个由Salvatore Sanfilippo写的key-value存储系统. Redis是一个开源的使用ANSI ...
- Mybaits API docs
http://www.mybatis.org/mybatis-3/apidocs/index.html
- Python中的 __name__有什么作用?最详细解读
案例说明: Python中的模块(.py文件)在创建之初会自动加载一些内建变量,__name__就是其中之一.Python模块中通常会定义很多变量和函数,这些变量和函数相当于模块中的一个功能,模块被导 ...
- java中函数的参数传递
转载 https://www.cnblogs.com/lixiaolun/p/4311863.html 转载https://www.cnblogs.com/wutianqi/p/8723582.ht ...
- node.js 使用 superagent 与 cheerio 完成简单爬虫
目标 建立一个 lesson3 项目,在其中编写代码. 当在浏览器中访问 http://localhost:3000/ 时,输出 CNode(https://cnodejs.org/ ) 社区首页的所 ...
- Python_day7
sys模块 import sys def _add(a, b): return a + b def _sub(a, b): return a - b def _mul(a, b): return a ...
- 中标麒麟(linux)下Qt调用python数据转换
转自:https://blog.csdn.net/itas109/article/details/78733478 mytest.py文件 # -*- coding: utf-8 -*- def he ...
- s6-5 TCP 连接的建立
TCP 连接的建立 采用三次握手建立连接 一方(server)被动地等待一个进来的连接请求 另一方(the client)通过发送连接请求,设置一些参数 服务器方回发确认应答 应答到达请求方,请求方最 ...