社区
Android
帖子详情
如何把Bitmap.createBitmap替换为BitmapFactory.decodeStream
ZGDZKJ22
2020-09-15 07:33:27
源代码为:Bitmap bitmap = Bitmap.createBitmap(mDIBPixels, mDIBWidth, mDIBHeight, Bitmap.Config.ARGB_8888);
mDIBPixels为int数组。由于createBitmap GC太严重,想替换成BitmapFactory.decodeStream(),如何实现?
...全文
8368
10
打赏
收藏
如何把Bitmap.createBitmap替换为BitmapFactory.decodeStream
源代码为:Bitmap bitmap = Bitmap.createBitmap(mDIBPixels, mDIBWidth, mDIBHeight, Bitmap.Config.ARGB_8888); mDIBPixels为int数组。由于createBitmap GC太严重,想替换成BitmapFactory.decodeStream(),如何实现?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
10 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
ZGDZKJ22
2020-09-17
打赏
举报
回复
public static Bitmap createBitmap(int[] colors, int width, int height, Bitmap.Config config) 这个函数根据颜色数组来创建位图,注意:颜色数组的长度>=width*height
ZGDZKJ22
2020-09-17
打赏
举报
回复
mDIBPixels用的int数组并且实时是变化的,没法用BitmapFactory.decodeByteArray
z71274520
2020-09-16
打赏
举报
回复
可以,来学习下~
weixin_43845112
2020-09-16
打赏
举报
回复
BitmapFactory.decodeByteArray这个呢?draw的频率应该会比你图片变化的频率高吧?你这样不是很容易outofmomary?
武雅姝
2020-09-16
打赏
举报
回复
回家可好可好
引用
ZGDZKJ22
2020-09-16
打赏
举报
回复
对啊,每次都是变化的
诉平生
2020-09-16
打赏
举报
回复
娄山说的没到了
weixin_43845112
2020-09-16
打赏
举报
回复
你再draw里面实时的创建bitmap去绘制,你难道每次draw,bitmap都变化,把bitmap弄成全局变量应该就行吧?
ZGDZKJ22
2020-09-15
打赏
举报
回复
上图是原函数
ZGDZKJ22
2020-09-15
打赏
举报
回复
public void drawDIB(Canvas canvas) { Bitmap bitmap = Bitmap.createBitmap(mDIBPixels, mDIBWidth, mDIBHeight, Bitmap.Config.ARGB_8888); Rect srcR, dstR; srcR = new Rect(0, 0, 0, 0); dstR = new Rect(0, 0, 0, 0); dstR = getDibShowRect(); srcR.right = mDIBWidth; srcR.left = mDIBWidth - dstR.width(); if (srcR.left < 0) srcR.left = 0; srcR.top = 0; srcR.bottom = mDIBHeight; MyApplication app; app = (MyApplication) (getContext().getApplicationContext()); int scanL; scanL = app.mRadarDevice.getScanLength(); if (scanL < mDIBHeight) srcR.bottom = scanL; canvas.drawBitmap(bitmap, srcR, dstR, null); bitmap.recycle(); boolean mBitMap = bitmap.isRecycled(); if (!mBitMap) { bitmap.recycle(); } else { bitmap = null; } // DebugUtil.i(TAG, // "srcR:="+srcR.left+";"+srcR.right+";"+srcR.top+";"+srcR.bottom); // DebugUtil.i(TAG,"dstR:="+dstR.left+";"+dstR.right+";"+dstR.top+";"+dstR.bottom); }
android
Bitmap
用法总结
.
create
Bitmap
( drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawable.getOpacity() != PixelFormat.OPAQUE ?
Bitmap
.Config.ARGB_8888 :
Bitmap
.Config.RGB_565); Canvas canvas = new Canvas...
android内存优化之图片优化
改用先通过
Bitmap
Factory
.
decode
Stream
方法,创建出一个
bitmap
,再将其设为ImageView的source,
decode
Stream
最大的秘密在于其直接调用JNI>>native
Decode
Asset()来完成
decode
,无需再使用java层的
create
Bitmap
,...
ViewPager或ImgeView加载图片出现内存溢出(OOM)
使用setImageResource或
Bitmap
Factory
.
decode
Resource来设置一张大图,因为这些函数在完成
decode
后,最终都是通过java层的
create
Bitmap
来完成的,需要消耗更多内存。解决方案:改用先通过
Bitmap
Factory
.
decode
Stream
...
Android 中对于图片的内存优化方法
尽量不要使用 setImage
Bitmap
、setImageResource、
Bitmap
Factory
.
decode
Resource 来设置一张大图,因为这些方法在完成
decode
后,最终都是通过 Java 层的
create
Bitmap
来完成的,需要消耗更多内存。因此,改用先...
使用
Bitmap
.
create
Bitmap
创建和
Bitmap
Factory
.
decode
....获取
Bitmap
对象
位图基本概念 位图文件的定义:扩展名可以是.bmp或者.dib,它将图像定义为由点(像素)组成,每...如一幅1024×768分辨率的32位真彩图片,其所占存储字节数为:1024×768×32/(8*1024)=3072KB 位图文件的特点:图像效
Android
80,349
社区成员
91,287
社区内容
发帖
与我相关
我的任务
Android
移动平台 Android
复制链接
扫一扫
分享
社区描述
移动平台 Android
android
android-studio
androidx
技术论坛(原bbs)
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章