Skip to main content
Participating Frequently
March 17, 2011
Question

BitmapData.draw - smoothing on Air on Android

  • March 17, 2011
  • 7 replies
  • 3085 views

Hi -

I'm trying to limit the number of textures I include in my package for a flash game I'm porting to Android using Air.

The game uses a blitting engine, and I am scaling the textures at runtime to use an appropriate sized bitmap for the different devices with their differing screen sizes.

This works absolutely fine on the desktop version of Air, but on the device itself any bitmapdata that is drawn at runtime does not seem to have smoothing applied - it all looks great as long as I the matrix used in the draw is never actually scaled.

Does smoothing work on bitmapdata.draw operations on Android?

Here's some code.

public function setupTexture($embedXML : Class, $bitmapData : BitmapData) : void {

     var $scaleFactor : Number = ViewSettings.getInstance().scaleFactor; //this is set

     var $matrix : Matrix = new Matrix();

     $matrix.scale($scaleFactor, $scaleFactor);

     _bitmapData = new BitmapData($bitmapData.width * $scaleFactor, $bitmapData.height * $scaleFactor, true, 0x00000000);

     _bitmapData.draw($bitmapData, $matrix, null, null, null, true);

     $bitmapData.dispose();

     var $ba : ByteArray = new $embedXML() as ByteArray;

     var $string : String = $ba.readUTFBytes($ba.length);

     var $xml : XML = new XML($string);

     initTextureAtlas($xml);

}

This topic has been closed for replies.

7 replies

Participating Frequently
August 4, 2011

i'm also finding this frustrating.. works fine on iOS.

Participating Frequently
March 17, 2011

Just to clarify :

The issue is the matrix used in the draw operation, if the matrix is scaled at all, then the resulting bitmapdata is aliased.

An identity matrix works fine.

It looks like I will have to provide a number of different texture sizes to support a range of android handsets.

This is a pain, I'm aware that bitmapdata.draw with smoothing on is slower than when it is off but I'm only performing this operation once.

Does anybody know of an alternative, perhaps an alchemy byte array option for the scaling down with anti-aliasing?

Participating Frequently
March 18, 2011

Turns out this flat-out doesn't work.  Bitmapdata.draw is cpu expensive with smoothing turned on, but I only needed it to work once.

Which is annoying - as android devices have many different screen resolutions and vector graphics don't work very well.

I've filed a bug, it's been acknowledged, I'll have to create a number of different texture atlas's for the most common devices.

If I get a chance I'm sure this can be done with a bytearray but I've not found an example of it yet.

March 20, 2011

We've experienced the same issue as you did while developing our game (http://market.android.com/details?id=air.com.tweegee.android.foodoohit), and as we wanted to use a single asset for all resolutions, we've eventually created a "bitmap loader" function/class.

this function simply receives a drawing object and scale factor, and returns a bitmapdata object (it just scales the drawing object off-screen and draws it on a new bitmapdata). this eliminates most of the scaling headaches.

this adds some loading time, and requires some thinking about memory, but it does work.

a quick tip - if you have several bitmap with the same graphics (tiles), create a single bitmapdata and point all the bitmaps to it.