Mastering the Tao of Personal Computing

my del.icio.us: ArticleS.UncleBob.TheThreeRulesOfTdd: Every programmer needs to bookmark this one http://bit.ly/6jONm 1 day ago

Flash Smoothing Issue

Jul 31st 2009
2 Comments
respond
trackback

Smoothing in Flash won’t work with every image. This is a bit of an old discovery, but yesterday I ran again into this issue and I had the luck to recall what was the reason for it, and decided to document it in my blog in case I run again into this issue.

Almost two years ago my colleague Barni and I literally spent half a day in finding what causes this behavior. We’ve tried everything - drawing the loaded bitmap into a new BitmapData-object with the smoothing argument set to true, but with no luck. And then it suddenly struck us - it was the image dimensions. Images that have an odd dimension(s) fail to be smoothed. Check the sample app beneath - choose a different image from the combo and observe whether the smoothing works for it:

The Solution

The solution is to create a new BitmapData-object that is always with even dimensions.

var smoothBitmapData : BitmapData = new BitmapData(
    loadedBitmap.width + (loadedBitmap.width % 2),
    loadedBitmap.height + (loadedBitmap.height % 2),
    true, 0x00FF0000);
smoothBitmapData.draw(
    loadedBitmap, null, null, null, null, true);

smoothBitmap = new Bitmap(
    smoothBitmapData, PixelSnapping.NEVER, true);

This is how it looks with the fix:

VIEW SOURCE


This post is tagged , , ,

2 Comments

  1. Thanks! I have been pulling my hair out trying to figure out why my image wouldn’t smooth!

    If found another “solution” which is to display the image at a scale of 0.999. This also forces smoothing for some reason.

  2. jag

    Thank you for sharing this.

    Thanks henk for the additional solution.

Incoming Links

Leave a Reply