gSkinner - Home

Minor Bug with Bitmap Smoothing in AS3

Posted on August 22, 2007 by Grant Skinner

We recently encountered a problem where bitmap images that we created dynamically were not being properly smoothed when rotated and scaled. We couldn’t see any obvious reason for it – we were setting the container bitmap to smooth, tried every quality setting, but it still looked terrible.

The answer turned out to be super simple, if not immediately obvious. The Bitmap object in ActionScript 3 reverts its .smoothing property to false whenever you change it’s .bitmapData property. Because we were setting up our Bitmap objects in advance, then assigning BitmapData objects to them when they were created, it simply appeared as though smoothing just didn’t work in our project.

Here’s a quick code example:

var bmp:Bitmap = new Bitmap(null,true);
trace(bmp.smoothing); // true
bmp.bitmapData = bmpd;
trace(bmp.smoothing); // false

And here’s what it looks like with smoothing on (top) versus off (bottom).




You can definitely see how our project wasn’t looking too good prior to fixing this issue.

Follow @gskinner on Twitter for more news and views on interactive media.
20 Comments

Great tip!

Posted by: Tink on Aug 22, 2007 4:18pm URL: http://www.tink.ws/blog

Thanks for mentioning! Will safe me a lot of time!

Posted by: Patrick Pietens on Aug 22, 2007 4:29pm URL: http://www.flashaddict.nl

Off topic: When I right click the SWF and select "Zoom In" the browser (FF) wants to add and entry "[Folder Name]" to my bookmarks... huh? I'm on a Mac right now, maybe thats it. Quirky little machines those Mac's...

Posted by: pan69 on Aug 22, 2007 5:57pm

@pan69

I ran into this problem yesterday afternoon while in development. It seems to be a Mac only bug with Firefox 2.0.0.6. It doesn't look like a Flash bug, but a browser bug. Hopefully it will be resolved in the next release/build of Firefox.

Quirky perhaps, but I still love my mac :)

Posted by: Nick on Aug 22, 2007 10:30pm URL: http://www.gskinner.com/blog

workaround in mxml

ViewHelper Class:

public static function smoothImage(event:Event):void

{

var bitmap:Bitmap = ((event.target as Image).content as Bitmap);

if (bitmap != null)

{

bitmap.smoothing = true;

}

}

Posted by: Claudius on Aug 23, 2007 6:29am

on complete not creationComplete

Posted by: Claudius on Aug 23, 2007 6:40am

Just came across with this bug. Thanks for the post.

Posted by: C4RL05 on Sep 10, 2007 4:46am URL: http://carlosulloa.com

Thanks for the tip. I just couldn't work out why my bitmaps looked so rubbish.

Posted by: Anon on Mar 31, 2008 3:38am

Can anyone explain my bitmap smoothing woes? Is it really just a limitation of Flash?

http://www.geocities.com/niquon/bitmap_test/

(watch small thumbnail when toggling quality)

and the thread on actionscript.org:

http://www.actionscript.org/forums/showthread.php3?p=745369

Posted by: Michael on May 20, 2008 9:27am

Thanks:)

I was crazy for few hours, almost thinking to switch project to HTML because of that :)

Than i run into this post

Posted by: young_moon on Nov 7, 2008 8:15am URL: http://www.martinswanviolins.com

SWEET, this explains everything...

Posted by: al on Feb 9, 2009 11:50am

Claudius - re your FLEX fix above (and just in case it helps anyone else) - works on Flash with the following var replaced:

var bitmap:Bitmap = (event.target.content as Bitmap);

I was going nuts trying to smooth dynamically loaded images - your function worked a treat!

Cheers

W

Posted by: Wayne on Feb 25, 2009 8:28am

This wasn't working for me with super small scaling (thumbnails) until I added this once my class was added to the stage:

stage.quality = StageQuality.BEST;

Posted by: Sundev on Oct 1, 2009 9:32am

I ran into the same problem, and I noticed that works if you initiate another object (Bitmap) set the new object bitmaData = yourBitmapData and then add smooting = true to Bitmap object

var bitmapOver:Bitmap = Bitmap(new OverFinal());

bitmapOver.smoothing = true;

ui11.addChild(bitmapOver);

//end adding png OVER

actualBMD = new BitmapData(ui11.width, ui11.height, true, 0xFFFFFFFF );

actualBMD.draw(ui11, new Matrix(), null, null, null, true );

var smoothTRY:Bitmap = new Bitmap(actualBMD);

smoothTRY.smoothing = true;

actualBMD = smoothTRY.bitmapData;

Posted by: Ionel on Oct 7, 2009 2:27pm URL: http://riaextended.com

This is working if you do:

var bitmap:Bitmap = new Bitmap(yourBitmapData)

bitmap.smooting = true;

now it works

Posted by: Ionel on Oct 7, 2009 2:31pm URL: http://riaextended.com

Nothing else seemed to work for me. If you apply a filter to the bitmap with 0 alpha, smoothing is added:

_bmp.filters = [new GlowFilter(0x000000, 0, 5, 5)];

Posted by: trent on Nov 18, 2009 1:37pm

what about bitmaps in the library nested in custom-class movieclips that are initiated dynamically?

do i need to acces the bitmap through code (movieclip.getchildat()) and re-assign smoothing = true?

Posted by: Saar on Mar 15, 2010 5:20am

ok i tested that and the answer is yes: you do have to reassign smoothing to library bitmaps like this:

Bitmap(myMovieClip.getChildAt(~)).smoothing = true;

cheers

Posted by: Saar on Mar 15, 2010 2:17pm

How can I make smooth my movie clip¿?
This is my code.

_root.createEmptyMovieClip("imageCentral_3",_root.getNextHighestDepth());
imageCentral_3._x = 700;
imageCentral_3._y = 150;
imageCentral_3._alpha = 100;
imageCentral_3._rotation = -4;
fullClipLoader.loadClip("images/imageCentral_3.jpg",imageCentral_3);

Posted by: Marco on Feb 10, 2011 11:15pm

Thanks folks! I am using two static BitmapData objects and swapping them out from under the displayed Bitmap when some action is performed. The same problem occurs. The first load looks nice, the subsequent ones look horrible. By resetting the smoothing property to true just after the swap, everything starts to spin right! Annoying little gremlin is quashed thanks to your post here.

Posted by: Abe K on Nov 10, 2011 7:02pm

Leave a Reply

Your email is never published nor shared.




You may use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">