Android的DrawBitMap使用ARGB

编程入门 行业动态 更新时间:2024-10-28 20:31:00
本文介绍了Android的DrawBitMap使用ARGB_8888时速度很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我发现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

本文发布于:2023-10-23 00:32:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519210.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Android   DrawBitMap   ARGB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!