...

View Full Version : BitmapData size problem



brbati
09-13-2010, 08:24 AM
BitmapData has limited size (2880x2880). How to create bitmap larger than that?

taguru
09-14-2010, 08:05 AM
Try this:

public class VirtualScreenBitmapData
{
private const maxWidth:int = 2880;

private var bitmapArray:Array;

private var width:int;
private var height:int;

public function VirtualScreenBitmapData(width:int, height:int, transparent:Boolean, fillColor:uint)
{
bitmapArray = new Array();

this.width = width;
this.height = height;

var count:int = Math.ceil(width/maxWidth);

for(var i:int=0; i<count; i++)
bitmapArray.push(new BitmapData(i<(count-1)?maxWidth:(width-(count-1)*maxWidth), height, transparent, fillColor));
}

public function get Width():int
{
return width;
}

public function get Height():int
{
return height;
}

public function Dispose():void
{
for(var i:int=0; i<bitmapArray.length; i++)
(bitmapArray[i] as BitmapData).dispose();
}

public function Draw(source:IBitmapDrawable):void
{
for(var i:int=0; i<bitmapArray.length; i++)
{
var mx:Matrix = i!=0?new Matrix(1, 0, 0, 1, -i*maxWidth):null;
(bitmapArray[i] as BitmapData).draw(source, mx);
}
}

public function CopyTo(dest:BitmapData, sourceRect:Rectangle, dx:int):void
{
var x1BitmapIndex:int = Math.floor(sourceRect.x/maxWidth);
var x1:int = sourceRect.x%maxWidth;
var x2BitmapIndex:int = Math.floor((sourceRect.x+sourceRect.width)/maxWidth);
var x2:int = (sourceRect.x+sourceRect.width)%maxWidth;
var left:int;

var rect1:Rectangle = new Rectangle(x1, 0, x1BitmapIndex==x2BitmapIndex?(x2-x1):(maxWidth-x1), height);
dest.copyPixels(bitmapArray[x1BitmapIndex], rect1, new Point(dx, 0));
left = dx+rect1.width;
for(var i:int=x1BitmapIndex+1; i<x2BitmapIndex; i++)
{
dest.copyPixels(bitmapArray[i], new Rectangle(0, 0, maxWidth, height), new Point(left, 0));
left += maxWidth;
}
if (x2BitmapIndex!=x1BitmapIndex)
dest.copyPixels(bitmapArray[x2BitmapIndex], new Rectangle(0, 0, x2, height), new Point(left, 0));
}
}

This class is part of finance ticker package. Visit http://www.ta-guru.com/ticker.php5 to download whole package. There you will see how you can use this class.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum