Smooth bitmap resize


/ Published in: ActionScript 3
Save to your folder(s)

Resizes BitmapData objects smoothly, using bilinear algorithm.


Copy this code and paste it in your HTML
  1. public static function resampleBitmapData (bmp: BitmapData, ratio: Number): BitmapData (
  2. if (ratio >= 1) { if (ratio> = 1) (
  3. return (BitmapManager.resizeBitmapData(bmp, ratio)); return (BitmapManager.resizeBitmapData (bmp, ratio));
  4. } )
  5. else { else (
  6. var bmpData:BitmapData = bmp.clone(); var bmpData: BitmapData bmp.clone = ();
  7. var appliedRatio:Number = 1; var appliedRatio: Number = 1;
  8.  
  9. do { do (
  10. if (ratio < 0.5 * appliedRatio if (ratio <0.5 * appliedRatio ) { ) (
  11. bmpData = BitmapManager.resizeBitmapData(bmpData, 0.5); bmpData = BitmapManager.resizeBitmapData (bmpData, 0.5);
  12. appliedRatio = 0.5 * appliedRatio; appliedRatio = 0.5 * appliedRatio;
  13. } )
  14. else { else (
  15. bmpData = BitmapManager.resizeBitmapData(bmpData, ratio / appliedRatio); bmpData = BitmapManager.resizeBitmapData (bmpData, ratio / appliedRatio);
  16. appliedRatio = ratio; appliedRatio = ratio;
  17. } )
  18. } while (appliedRatio != ratio); ) While (appliedRatio! = Ratio);
  19.  
  20. return (bmpData); return (bmpData);
  21. } )
  22. } )

URL: http://www.envrac.org/index.php/2008/06/23/181-reduction-de-bitmapdata-smoothing-pourquoi-c-est-pas-beau-et-comment-ameliorer

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.