Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了使用ARGB_8888时,Android DrawBitMap非常慢大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我发现DrawBitMap需要50-60毫秒才能绘制三个位图,一个是占据整个屏幕的矩形,一个是圆形,另一个是路径.我的位图是通过在空白位图上使用Canvas.drawPath,drawRect和drawCircle创建的,其中Bitmap.Config为ARGB_8888.
我正在使用ARGB_8888使背景可见以获得分层效果.
我很震惊地发现时间大约为50ms,因为我认为drawBitmap是一个非常简单的操作.有人可以指导我是否有任何根本性的错误.以下是我的代码

创建空白位图

Rectangle = Bitmap.createBitmap(320,480,Bitmap.Config.ARGB_8888);
Circle = Bitmap.createBitmap(70,70,Bitmap.Config.ARGB_8888);
Leaf1 = Bitmap.createBitmap(20,30,Bitmap.Config.ARGB_8888);

在适当的BitMap上绘制形状

Canvas c = new  Canvas(RectanglE);
Paint p = new Paint();
p.setAntiAlias(true);
p.setColor(0xff6e8b3E);
c.drawRect(0,320,p);

Canvas c = new Canvas(CirclE);
Paint p = new Paint();
CirclePath = new Path();
p.setAntiAlias(true);
p.setColor(0xffcd661d);
System.out.println("x = "+x+" y = "+y);
CirclePath.addCircle(50,50,10,Path.Direction.CW);
c.drawPath(CirclePath,p);

Canvas c = new  Canvas(Leaf1);
Paint paint = new Paint();
Path path = new Path();
paint.setAntiAlias(true);
path.moveTo((float)184.37,(float)219.15);
path.cubicTo((float)188.32,(float)219.15,(float)192.88,(float)220.44,(float)195.62,(float)223.54);
path.cubicTo((float)197.84,(float)226.05,(float)203.2,(float)229.84,(float)198.18,(float)245.98);

在OnDraw中绘制BitMap

canvas.drawBitmap(Rectangle,p);
canvas.translate(x,y); // For animation effect
canvas.drawBitmap(Circle,p);
canvas.drawBitmap(Leaf1,p);

现在,当我记录这三个drawBitMap的时间时,我发现它需要大约50ms
代码中是否存在重大错误.将Bitmap.Config更改为RGB_565会将时间缩短到8毫秒左右,但背景不可见,我在路径周围有一个黑框

@H_450_19@

解决方法

看起来很正常
画布在透明度上非常慢.

您可以尝试切换到OpenGL ES或尽可能少透明地设计内容,这样您就可以尽可能频繁地使用RGB_565.

@H_450_19@ @H_450_19@

大佬总结

以上是大佬教程为你收集整理的使用ARGB_8888时,Android DrawBitMap非常慢全部内容,希望文章能够帮你解决使用ARGB_8888时,Android DrawBitMap非常慢所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。