com.neolao.data.BitmapDataUtils
Methodes utiles sur les BitmapData.
Méthodes
Visibilité | Return | Nom | Param 1 | Param 2 | Param 3 | Description |
---|---|---|---|---|---|---|
static public | BitmapData | resize | pBitmap:BitmapData | pWidth:Number | pHeight:Number | Redimensionne un BitmapData |
Source
import flash.display.BitmapData; import flash.geom.Rectangle; /** * ATTENTION : UTF-8 (éàöù) * * [26/10/2004] Version 1.0 * Création de la méthode resize * @ignore * * Methodes utiles sur les BitmapData * @author neolao <neo@neolao.com> * @version 1.0 (26/10/2004) * @link http://resources.neolao.com/flash_fp8/classes/data/BitmapDataUtils * @license http://creativecommons.org/licenses/by-sa/2.5/ */ class com.neolao.data.BitmapDataUtils{ public static var className:String = "BitmapDataUtils"; public static var version:String = "1.0"; // ----------------------------- CONSTANTES -------------------------------- // ----------------------------- VARIABLES --------------------------------- /*========================== METHODES PUBLIQUES ==========================*/ /*========================================================================*/ /** * Redimensionne un BitmapData * @param pBitmapData Le BitmapData à redimensinoner * @param pWidth [optional] La largeur * @param pHeight [optionnal] La hauteur * @return Le BitmapData redimensionné */ static public function resize(pBitmapData:BitmapData, pWidth:Number, pHeight:Number):BitmapData{ pWidth = (pWidth > 0)?pWidth:pBitmapData.width; pHeight = (pHeight > 0)?pHeight:pBitmapData.height; var mc:MovieClip = _root.createEmptyMovieClip("BitmapDataUtils_temp", _root.getNextHighestDepth()); var mc2:MovieClip = mc.createEmptyMovieClip("img", mc.getNextHighestDepth()); var rect:Rectangle = new Rectangle(0, 0, pWidth, pHeight); var bd:BitmapData = new BitmapData(pWidth, pHeight); var result:BitmapData = new BitmapData(pWidth, pHeight); // zone invisible bd.fillRect(rect, 0); mc.attachBitmap(bd, mc.getNextHighestDepth()); // l'image mc2.attachBitmap(pBitmapData, 1); // Redimensionner if(mc2._width > pWidth){ mc2._width = pWidth; mc2._yscale = mc2._xscale; } if(mc2._height > pHeight){ mc2._height = pHeight; mc2._xscale = mc2._yscale; } if(mc2._width < pWidth && mc2._height < pHeight){ mc2._width = pWidth; mc2._yscale = mc2._xscale; if(mc2._height > pHeight){ mc2._height = pHeight; mc2._xscale = mc2._yscale; } } // centrer if(mc2._width < mc._width){ mc2._x = (mc._width - mc2._width)/2; } if(mc2._height < mc._height){ mc2._y = (mc._height - mc2._height)/2; } // enregistrement result.draw(mc); // destruction mc.removeMovieClip(); return result; } /*==================== FIN = METHODES PUBLIQUES = FIN ====================*/ /*========================================================================*/ }