BitmapData

Hello everybody… I have a problem with the new BitmapData class

I have a BitmapData object(used for copying a mc) but I want the rectangle associated to start from a different value than 0, 0. Is there any other way to change this rather than changing the coordinates of the movie clip it will copy?

I use the .draw method to copy from the source mc

Thanks

just choose a different coordinate when yo start the draw, post your code.

the class i am using is taken from this tutorial: http://www.sephiroth.it/tutorials/flashPHP/print_screen/



import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.ColorTransform;
/**
 * Little and simple print flash screen class
 */
class it.sephiroth.PrintScreen {
	public var addListener:Function;
	public var broadcastMessage:Function;
	private var id:Number;
	public var record:LoadVars;
	function PrintScreen() {
		AsBroadcaster.initialize(this);
	}
	public function print(mc:MovieClip, x:Number, y:Number, w:Number, h:Number) {
		broadcastMessage("onStart", mc);
		if (x == undefined) {
			x = 0;
		}
		if (y == undefined) {
			y = 0;
		}
		if (w == undefined) {
			w = mc._width;
		}
		if (h == undefined) {
			h = mc._height;
		}
		[COLOR="Red"]var bmp:BitmapData = new BitmapData(w+x, h+y, false);[/COLOR]
		record = new LoadVars();
		record.width = w;
		record.height = h;
		record.cols = 0;
		record.rows = 0;
		bmp.draw(mc, mc.transform.matrix, new ColorTransform(), 1, new Rectangle(x, y, w, h));
		id = setInterval(copysource, 5, this, mc, bmp, x, y);
	}
	private function copysource(scope, movie, bit, xS, yS) {
		var pixel:Number;
		var str_pixel:String;
		scope.record["px"+scope.record.rows] = new Array();
		for (var a = 0; a<bit.width; a++) {
			pixel = bit.getPixel(a+xS, (scope.record.rows+yS));
			str_pixel = pixel.toString(16);
			if (pixel == 0xFFFFFF) {
				str_pixel = "";
			}
			// don't send blank pixel   
			scope.record["px"+scope.record.rows].push(str_pixel);
		}
		scope.broadcastMessage("onProgress", movie, scope.record.rows, bit.height);
		// send back the progress status
		scope.record.rows += 1;
		if (scope.record.rows>=bit.height) {
			clearInterval(scope.id);
			scope.broadcastMessage("onComplete", movie, scope.record);
			// completed!
			bit.dispose();
		}
	}
}



let’s say i have a 200x300 mc named test at (0,0) on the root but i want to copy only the pixels starting at (100,100)(this would create a 100x200 rectangle) the above code creates a new rectangle starting from 0,0 and ending at (200,300)… if i set [COLOR=“Red”]var bmp:BitmapData = new BitmapData(w, h, false)[/COLOR] it would not copy all the pixels beacause the BitmapData rectangle would start from the (0,0) coordinates and not (100,100)… if there would be a way to move the BitmapData rectangle to (100,100) the code would work perfect. But i don’t know that way and i have to create a bigger BitmapData rectangle so I can copy all the pixels I am interested in(w+x and h+y) I hope you understand what I mean

x, y -> the position where copying starts
w,h -> width, height of the copy rectangle

Thank you

also, is there a way to reduce the memory usage for the BitmapData class?