2

I am drawing bitmaps on the canvas using bitmap factory(see P.S.). I also have an animation applyed to my bitmap. I use bitMapFactory.options with options.inScaled = false; options.inDither = true;

The problem is when I draw my bitmap which is 100x100 size on smaller devices it rescales it automatically to smaller which is ok. The problem is when I draw it to a 10" device it scales it to be bigger but the image quality is lost. This isn't actually a problem. The problem is that the animation gets very slow even if the 10" device has way better hardware specs than the smaller ones I used.

Is there a way so that I can improve the speed for when the device draws bitmaps rescaled to bigger than their original size?

P.S.(I use BitmapFactory.decodeResource(mContext.getResources(),R.drawable.example, options);before onDraw is called in the beggining and on canvas I use drawBitmap.)

Fofole
  • 3,398
  • 8
  • 38
  • 59

2 Answers2

2

I am drawing bitmaps on the canvas using bitmap factory

That's very cruel. BitmapFactory does not draw anything. It just loads the bitmap. I hope you don't load the Bitmap everytime a draw is invoked (Think that's what you tried to clarify with the last sentence:), still kinda confusing).

It came out that the loaded bitmaps should have THE SAME format as the display has.

Without code one can't say more!

poitroae
  • 21,129
  • 10
  • 63
  • 81
  • Ok just to be clear the drawing part is ok. The images are loaded using bitmapFactory before the onDraw method is called. In onDraw I draw the bitmap using drawBitmap. My only problem is that my bitmap is 100x100. So it is auto-resized to fit on the screen(which could turn the bitmap to be smaller or bigger;if it is smaller the resize is ok, if the image is bigger, it slows down my tablet 3x). – Fofole Nov 30 '11 at 13:32
  • 1
    If you are working on android 3.0 or above, you can set the tag "android:hardwareAccelerated='true'" in your manifest.xml to an activity/application to let the GPU do the render stuff instead of the CPU. Again, make sure the bitmaps loading format and the display format are the same. You can get the bitmap's format with bitmap.getConfig(). Set the display format with getWindow().setFormat(PixelFormat.YOUR_CHOICE); – poitroae Nov 30 '11 at 13:48
  • Cool, what exactly did help? Adding hardware acceleration or synchronizing the image formats? Please mark the post as answer to show others that this issue was solved. – poitroae Nov 30 '11 at 16:17
1

may be this post can help you

http://www.reddit.com/r/androiddev/comments/l46jn/why_is_android_still_auto_scaling_my_bitmaps/

webshaker
  • 467
  • 6
  • 17
  • This would be ok. But I want to use the auto-scaling done by android. I don't even mind the image quality droping down. I only hate that is gets 3x slower for some reason and maybe there is a way to fix it. Still 10x for trying to help +1. – Fofole Nov 30 '11 at 13:28
  • Don't use autoscale, make your own scale depending on the device résolution and then use this "precalculated" scaled bitmap. use createScaledBitmap for that. – webshaker Nov 30 '11 at 16:12