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:

you rock said...

you are awesome. i've been trying to figure out the smoothing thing with components and have gotten nowhere. your code snippet was perfect. thanks.

nypo said...

No worries. Always a pleasure to help - glad you found it useful

LaloshDesign said...

Thanks so much for this! I've been searching for video smoothing in Flash and I agree that its bizarre that this isn't more widely known. Doesn't anyone else scale video???
Thanks again!!

Anonymous said...

Thanks
this statement placed after the std flash component ( case handling matters )

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

works so damn well that i am stunned that its not in the params list for that component.

Thx again - i owe you one since my magazine is fully scaled but in bitmap , text , video .. etc all kind of unknown screen resolutions now get a nice outcome.Proof:

http://ctngreen.com/2008/nov

BTW some pre processing of the video ( using Vegas its the Sony Quick Blur plugin set at .35 works nicely. ) will take some of the sting out of logos and titling and jpg pan-zoom rotate inside the video - used with this flash smoothing object call, it makes everything work. Finally.

nypo said...

Really glad I could help. Had a look at your site. Nice :) Seems you have a lot of video content on there. Just glad I could help.