Android DrawBitMap is very slow when using ARGB_8888

I find that DrawBitMap takes 50-60 ms to draw only three raster images, one of which is a rectangle occupying the entire screen, one is a circle, and the other is a path. My bitmaps are created using Canvas.drawPath, drawRect and drawCircle on an empty bitmap with Bitmap.Config as ARGB_8888. I use ARGB_8888 to make the background visible to get a layering effect. I was shocked when I found a time of about 50 ms, since I thought drawBitmap would be a very simple operation. Can someone explain if there is any fundamental mistake that I am making. Below is my code

Create blank bitmaps

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); 

Drawing figures on the corresponding 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); 

Drawing BitMap in 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); 

Now, when I record the time spent on these three drawBitMap, I find that it takes about 50 ms. There is something big in the code. Changing Bitmap.Config to RGB_565 reduces the time to 8 ms, but then the background is not displayed, and I get a black box around the path

+6
android
source share
3 answers

It looks fine. Canvas is very slow in transparency.

You can either try switching to OpenGL ES, or create your content with minimal transparency so that you can use RGB_565 as often as possible.

+6
source share

You should always match the format of your screen. Recently, there was a very similar question, and Romain mentioned that glare essentially turns into memcpys if the format matches. And, of course, make sure you are not using esoteric blit mode.

Also, why do you use anti-aliasing if you don't scale / rotate anything?

As for 565, it doesn’t work - I'm just looking at your code. Do you use alpha channel? What do your bitmaps look like?

+2
source share

One of the Android developers explains this here . To draw ARGB_8888 quickly, you need to draw a 32-bit window. See the bottom of the article for tests.

0
source share

All Articles