/ Published in: ActionScript 3
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
private static const SCALE_DROP:Number = .5; public function resample(bitmapData:BitmapData, newWidth:uint, newHeight:uint):BitmapData { var finalScale:Number = Math.min(newWidth/bitmapData.width, newHeight/bitmapData.height); var finalData:BitmapData = bitmapData; if (finalScale> 1) { finalData = new BitmapData(bitmapData.width*finalScale, bitmapData.height*finalScale, true, 0); finalData.draw(bitmapData, new Matrix(finalScale, 0, 0, finalScale), null, null, null, true); return finalData; } var drop:Number = SCALE_DROP; var initialScale:Number = finalScale; while (initialScale/drop <1) initialScale /= drop; var bd:BitmapData = new BitmapData(Math.ceil(bitmapData.width*initialScale), Math.ceil(bitmapData.height*initialScale)); bd.draw(finalData, new Matrix(initialScale, 0, 0, initialScale), null, null, null, true); finalData = bd; for (var scale:Number = initialScale*drop; Math.round(scale*1000)>= Math.round(finalScale*1000); scale *= drop) { bd = new BitmapData(Math.ceil(bitmapData.width*scale), Math.ceil(bitmapData.height*scale)); bd.draw(finalData, new Matrix(drop, 0, 0, drop), null, null, null, true); finalData = bd; } return finalData; }
URL: http://jacwright.com/blog/221/high-quality-high-performance-thumbnails-in-flash/