Mastering the Tao of Personal Computing

Great maxim to follow: From reading the code, one should be able to tell what the code does, but also why it does it. npacemo's twitter

Flash Smoothing Issue

Jul 31st 2009
4 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 , , ,

4 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.

  3. Casey

    Man, that must have been incredibly frustrating.

  4. otomo

    great tip, thanks for sharing.

Incoming Links

Leave a Reply

STOP SOPA

Imagine a World Without Free Knowledge

Right now, the U.S. Congress is considering legislation that could fatally damage the free and open Internet. To raise awareness, I'm blacking out my blog.