Bilinear Bitmap scaling


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



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.