我发现DrawBitMap正在50-60毫秒绘制只有三个位图的是矩形占据整个屏幕,一个是圆形,另外一个是路径。我的位图使用Canvas.drawPath,drawRect的和画圆上的一个空白位图与Bitmap.Config为ARGB_8888创建。 我使用ARGB_8888使背景可见获得分层的效果。 我很震惊地发现作为50毫秒左右的时间,因为我以为drawBitmap将是一个非常简单的操作。可有人指导,以有,我做任何根本性的错误。以下是我的code
I find that DrawBitMap is taking 50-60 ms for drawing just three bitmaps one is a rectangle occupying the full screen, one is a circle and another one is a Path. My bitmaps are created by using Canvas.drawPath, drawRect and drawCircle on a blank bitmap with the Bitmap.Config as ARGB_8888. I am using ARGB_8888 to make the background visible to get a layering effect. I was shocked to find the time taken as around 50ms as I thought drawBitmap would be a very simple operation. Can someone guide as to is there any fundamental mistake that I am making. Following is my code
创建空白位图
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,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);
绘制位图的OnDraw
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);现在,当我记录采取这三款drawBitMap我发现它正在围绕50毫秒的时间 是不是有什么大的时候失误了code。更改Bitmap.Config到RGB_565带来的时间缩短到大约8毫秒但背景是不可见的,我得到一个黑盒子周围的路径
Now when I record the time taken for this three drawBitMap I find it is taking around 50ms Is there something big time mistake in the code. Changing the Bitmap.Config to RGB_565 brings the time down to around 8ms but then the background is not visible and I am getting a black box around the path
推荐答案看起来正常。 Canvas是透明度非常慢。
Looks normal. Canvas is very slow on transparency.
您可以尝试切换到OpenGL ES的或用尽可能少的透明地设计自己的内容,以便您可以使用RGB_565尽可能多地。
You can either try to switch to OpenGL ES or design your content with as little transparency as possible so you can use RGB_565 as often as possible.
更多推荐
Android的DrawBitMap使用ARGB
发布评论