Flash/ActionScript3 crashes on getPixel/32
- by Quandary
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);