SML: Code: ImageData
import flash.display.BitmapData;
/**
 * Image Data extraction class
 *
 * @author See-ming Lee <seeminglee+sml@gmail.com>
 * 
 * SVN
 * $LastChangedRevision:: 19                                                      $
 * $LastChangedBy:: seeminglee                                                    $
 * $LastChangedDate:: 2007-10-12 17:28:28 -0400 (Fri, 12 Oct 2007)                $
 * $HeadURL:: http://svn1.cvsdude.com/seeminglee/SML/trunk/projects/image-data/sr#$
 * $Id:: ImageData.as 81 2007-10-12 21:28:28Z seeminglee                          $
 */
class sml.ImageData 
{

    /**
     * Property: bitmap symbolID in the library
     */
    private var $bitmapSymbolID:String;
    public function get bitmapSymbolID():String
    {
        return $bitmapSymbolID;
    }
    public function set bitmapSymbolID(a:String):Void
    {
        $bitmapSymbolID = a;

        // load the bitmap
        $bitmapData = BitmapData.loadBitmap(bitmapSymbolID);

        // reset the pixelArray
        delete $pixelArray;
    }

    /**
     * Property: bitmap data
     */
    private var $bitmapData:BitmapData;
    public function get bitmapData():BitmapData
    {
        return $bitmapData;
    }

    /**
     * Property: an array of pixel color values
     */
    private var $pixelArray:Array;
    public function get pixelArray():Array
    {
        if ($pixelArray==undefined)
        {
            $pixelArray = new Array();
            var w:Number = bitmapData.width;
            var h:Number = bitmapData.height;
            for (var i:Number=0; i<w; i++)
            {
                $pixelArray[i] = new Array();
                for (var j:Number=0; j<h; j++)
                {
                    $pixelArray[i][j] = getPixelRGB(i,j);
                }
            }
        }
        return $pixelArray;
    }

    /**
     * Constructor
     */
    public function ImageData()
    {
        $pixelArray = new Array();
    }

    /**
     * Returns the RGB value of a pixel
     * @param x the x-coordinate of the pixel as a number
     * @param y the y-coordinate of the pixel as a number
     */
    public function getPixelRGB(x:Number, y:Number):Number
    {
        return bitmapData.getPixel(x, y);
    }

    /**
     * Returns the RGB value of a pixel as a hex string.
     * @param x the x-coordinate of the pixel as a number
     * @param y the y-coordinate of the pixel as a number
     */
    public function getPixelHEX(x:Number, y:Number):String
    {
        return bitmapData.getPixel(x, y).toString(16);
    }
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License