All pastes #758917 Raw Edit

Someone

public text v1 · immutable
·published 2007-11-02 18:01 UTC
rendered paste body
import flash.display.*;
import flash.geom.*;
import flash.utils.*;

var f:BitmapData = new g(-1,-1);
var j:BitmapData = new jpg(-1,-1);

var t:Number = getTimer();

var r:BitmapData = new BitmapData(150,100,false,0xff0000);
resizeBitmapData(r,f,false);

trace("end msg: ",getTimer()-t);

for(var i =0;i<5;i++){
	var b:Bitmap = new Bitmap(r);
	b.y = 50;
	b.x = (r.width+10) * i;
	addChild(b);
}

trace(r.rect);

function resizeBitmapData(result:BitmapData,source:BitmapData,cut:Boolean):void {
	var s:Number,x:int,y:int;
	if(cut){
		s = Math.max(result.rect.width/source.rect.width,result.rect.height/source.rect.height);
		x = Math.round((result.rect.width-source.rect.width*s)/2);
		y = Math.round((result.rect.height-source.rect.height*s)/2);
	}else{
		s = Math.min(result.rect.width/source.rect.width,result.rect.height/source.rect.height);
		x = Math.round((result.rect.width-source.rect.width*s)/2);
		y = Math.round((result.rect.height-source.rect.height*s)/2);
	}
	
	var m:Matrix = new Matrix();
	m.scale(s,s);
	m.translate(x,y);
	result.draw(source,m);
	trace(m);
}
var c:Boolean;

bt.addEventListener("click",function(e:Event){
	if(c){
		r.fillRect(r.rect, 0x0000FF);
		resizeBitmapData(r,f,false);
	}else{
		r.fillRect(r.rect, 0x0000FF);
		resizeBitmapData(r,j,false);
	}
	c = !c;
	trace("eooo");
})