Posted By

superflip on 09/10/09


Tagged

as3 bitmap scaling


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

toxin20
paulheyer


Bilinear Bitmap scaling


 / Published in: ActionScript 3
 

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

Report this snippet  

You need to login to post a comment.