Flash/ActionScript3 crashes on getPixel/32

Posted by Quandary on Stack Overflow See other posts from Stack Overflow or by Quandary
Published on 2010-03-18T20:35:40Z Indexed on 2010/03/18 20:51 UTC
Read the original article Hit count: 584

Question: The below code crashes flash... Why?

The crash causing lines seem to be


//var uiColor:uint = bmpd.getPixel(i,j);
var uiColor:uint = bmpd.getPixel32(i,j);
trace("Color: "+ uiColor);

I am trying to take a snapshot of a movieclip and iterate through all pixels in the image and get the pixel's color.

import flash.display.BitmapData;
import flash.geom.*;


function takeSnapshot(mc:MovieClip):BitmapData 
{
var sp:BitmapData = new BitmapData(mc.width, mc.height, true, 0x000000);
sp.draw(mc, new Matrix(), new ColorTransform(), "normal");
return sp;
}

var mcMyClip:MovieClip=new MovieClip()
var xxx:cMovieClipLoader=new cMovieClipLoader(); 

xxx.LoadImageAbsSize(mcMyClip,"http://localhost/flash/images/picture.gif", 500,500)

//this.addChild(mcMyClip);

function WhenImageIsLoaded()
{
var bmpd:BitmapData=takeSnapshot(mcMyClip);

var i,j:uint;

for(i=0; i < bmpd.width;++i)
{
    for(j=0; j < bmpd.height;++j)
    {
        //var uiColor:uint = bmpd.getPixel(i,j);
        var uiColor:uint = bmpd.getPixel32(i,j);
        trace("Color: "+ uiColor);
    }
}


var myBitmap:Bitmap = new Bitmap(bmpd);



this.addChild(myBitmap);
}

setTimeout(WhenImageIsLoaded,1000);

© Stack Overflow or respective owner

Related posts about as3

Related posts about actionscript-3