package net.fdms.Function.ImageHandle 
{
	import flash.display.Bitmap;
	/**
	 * 2011/7/4 16:48
	 * @author Dawnboy
	 */
	public class ImageZoom 
	{
		
		public function ImageZoom() 
		{
		}
		
		public static function zoom(bitmap:Bitmap,MaxWidth:Number,MaxHeight:Number,oveflow:Boolean = true,overflowType:int = 0,scaleMax:Boolean = false):Bitmap {
			
			var foo:Bitmap = new Bitmap(bitmap.bitmapData, "auto", true);
			var oldW:Number = foo.width;
			var oldH:Number = foo.height;
			
				if (foo.width > MaxWidth && foo.height > MaxHeight) {
					if (oveflow) {
						switch(overflowType) {
							case 0:
								foo.width = MaxWidth;
								if (MaxWidth /oldW  * oldH < MaxHeight) {
									foo.height = MaxHeight;
									foo.width = MaxHeight / oldH * oldW;
								}else {
									foo.height = MaxWidth / oldW * oldH;
								}
								break;
							case 1:
								foo.width = MaxWidth;
								foo.height = MaxWidth / oldW * oldH;
								break;
							case 2:
								foo.height = MaxHeight;
								foo.width = MaxHeight / oldH * oldW;
								break;
						}
					}else{
						foo.width = MaxWidth;
						if (MaxWidth /oldW  * oldH > MaxHeight) {
							foo.height = MaxHeight;
							foo.width = MaxHeight / oldH * oldW;
						}else {
							foo.height = MaxWidth / oldW * oldH;
						}
					}
				}else if(foo.width>MaxWidth && foo.height<MaxHeight) {
					foo.width = MaxWidth;
					foo.height = MaxWidth / oldW * oldH;
				}else if(foo.width<MaxWidth && foo.height>MaxHeight){
					foo.height = MaxHeight;
					foo.width = MaxHeight / oldH * oldW;
				}else {
					if (scaleMax) {
						foo.width = MaxWidth;
						if (MaxWidth /oldW  * oldH < MaxHeight) {
							foo.height = MaxHeight;
							foo.width = MaxHeight / oldH * oldW;
						}else {
							foo.height = MaxWidth / oldW * oldH;
						}
					}
				}
			
			return foo;
		}
		
	}

}