Blog

Thursday 6 March 2008

Image and video smoothing with actionscript

Image Smoothing

For some reason when Adobe released Flash 8 they gave the user the option as to whether to smooth an imported image or not. In the past this has been done by default and I can't really see why anyone would want the image not to be smoothed when scaling up but maybe that's just me. You now need to right click the image in the library and allow smoothing. This is all well and good when you have the image in your library but if you want to smooth an image that is being dynamically passed in your a bit stuck. Well, not anymore thanks to a recent tutorial I found on Frontend Multimedia .

Simply add this chunk of code to the top of your frame 1 actionscript exactly as is:

_global.smoothImageLoad = function(imgURL, targetMovie) {
var i=0
do { i++ } while (eval("_root.smoothImageLoadTemp"+i) != undefined)
tmc = _root.createEmptyMovieClip("smoothImageLoadTemp"+i, _root.getNextHighestDepth())
tmc.createEmptyMovieClip("ti", tmc.getNextHighestDepth())
tmc.tm = targetMovie
with(tmc) {
tmcl = new MovieClipLoader()
tmcl.onLoadComplete = function() {
ti.onEnterFrame = function() {
pixelData = new flash.display.BitmapData(ti._width, ti._height);
pixelData.draw(ti);
tm.attachBitmap(pixelData, 1, true, true);
tm.smoothImageLoadComplete()
removeMovieClip(ti._parent)
}
}
tmcl.loadClip(imgURL, tmc.ti)
}
}

Then all you need to do is add in:

smoothImageLoad("image.jpg", mytargetmc)

Where image can be the path to your image and mytargetmc is an empty movieclip with that instance name that your image will be passed into. Hey presto - a nice smoothed image.

Video Smoothing

Even more baffling is the fact that the ability to smooth a video seems to be relatively hidden and unknown of. It is as simple as adding in:

flvPlayback.getVideoPlayer(flvPlayback.activeVideoPlayerIndex) ._video.smoothing = true;

Where flvPlyaback is the instance name of your flvplayback component dragged to the stage from your components library. Personally I'd have thought this would be something Adobe would be shouting about as there is far too much bad quality video online that could be improved by this one line of code.

Well, there you have it. Hope you found it useful. Anyone have any experience with this or can further improve this little bit of advice feel free to comment or get in touch.

5 comments: