# BitmapData

**URL:** <https://forum.kirupa.com/t/bitmapdata/185345>\
**Category:** flash\
**Created:** [April 12, 2006, 5:23pm UTC](https://forum.kirupa.com/t/bitmapdata/185345 "2006-04-12T17:23:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dominus](https://avatars.discourse-cdn.com/v4/letter/d/b5ac83/32.png) [@dominus](https://forum.kirupa.com/u/dominus)\
**Post date:** [April 12, 2006, 5:23pm UTC](https://forum.kirupa.com/t/bitmapdata/185345/1 "2006-04-12T17:23:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)\
**Post date:** [April 12, 2006, 5:29pm UTC](https://forum.kirupa.com/t/bitmapdata/185345/2 "2006-04-12T17:29:13Z")

</div>

> [@dominus](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![dominus](https://avatars.discourse-cdn.com/v4/letter/d/b5ac83/32.png) [@dominus](https://forum.kirupa.com/u/dominus)\
**Post date:** [April 14, 2006, 2:26pm UTC](https://forum.kirupa.com/t/bitmapdata/185345/3 "2006-04-14T14:26:56Z")

</div>

the class i am using is taken from this tutorial: [http://www.sephiroth.it/tutorials/flashPHP/print\_screen/](http://www.sephiroth.it/tutorials/flashPHP/print_screen/)

```auto

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

---

<div class="post-metadata">

**Author:** ![dominus](https://avatars.discourse-cdn.com/v4/letter/d/b5ac83/32.png) [@dominus](https://forum.kirupa.com/u/dominus)\
**Post date:** [April 14, 2006, 2:27pm UTC](https://forum.kirupa.com/t/bitmapdata/185345/4 "2006-04-14T14:27:49Z")

</div>

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