我发现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);
Run Code Online (Sandbox Code Playgroud)
在适当的BitMap上绘制形状
Canvas c = new Canvas(Rectangle);
Paint p = new Paint();
p.setAntiAlias(true);
p.setColor(0xff6e8b3e);
c.drawRect(0,0,320,480,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);
Run Code Online (Sandbox Code Playgroud)
在OnDraw中绘制BitMap
canvas.drawBitmap(Rectangle,0,0,p);
canvas.translate(x,y); // For animation effect
canvas.drawBitmap(Circle,0,0,p);
canvas.drawBitmap(Leaf1,0,0,p);
Run Code Online (Sandbox Code Playgroud)
现在,当我记录这三个drawBitMap所花费的时间时,我发现它需要大约50ms.代码中是否存在大的时间错误.将Bitmap.Config更改为RGB_565会将时间缩短到8毫秒左右,但背景不可见,我在路径周围有一个黑框
您应该始终匹配屏幕的格式。最近有一个非常类似的问题,Romain 提到如果格式匹配,blit 本质上会变成 memcpys。当然,请确保您没有使用深奥的 blit 模式。
另外,如果你不缩放/旋转任何东西,为什么要使用抗锯齿呢?
至于 565 不起作用 - 我只是浏览一下你的代码。您使用的是 Alpha 通道吗?您的位图到底是什么样子的?
| 归档时间: |
|
| 查看次数: |
10019 次 |
| 最近记录: |