如何把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 打赏 收藏 转发到动态 举报
写回复
用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); }

80,349

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧