flex图片导出

			public function exportChart(d:DisplayObject):void{
				var dt:DisplayObject = d;
				var bd:BitmapData = getBitMapData(dt,dt.parent);   
				var fr:Object = new FileReference();
				if(fr.hasOwnProperty("save")){
					var encoder:PNGEncoder = new PNGEncoder();
					var data:ByteArray = encoder.encode(bd);
					fr.save(data,'chart.png');
				}else{
					Alert.show("当前flash player版本不支持此功能,请安装10.0.0以上版本!","提示");
				}
			} 
			//获得对象的BitMapData
			public function getBitMapData(mc:DisplayObject,container:DisplayObjectContainer):BitmapData{
				var bmpData:BitmapData = new BitmapData(mc.width,mc.height,true,0x00ffffff);
				var bounds:Object = mc.getBounds(mc);
				var bounds2:Object = container.getBounds(container);
				var matrix:Matrix = mc.transform.matrix.clone();
				var point0:Point = container.globalToLocal(mc.localToGlobal(new Point(bounds.x,bounds.y)));
				var point1:Point = container.globalToLocal(mc.localToGlobal(new Point(bounds.x,bounds.y+bounds.height)));
				var point2:Point = container.globalToLocal(mc.localToGlobal(new Point(bounds.x+bounds.width,bounds.y)));
				var point3:Point = container.globalToLocal(mc.localToGlobal(new Point(bounds.x+bounds.width,bounds.y+bounds.height)));
				var point:Point = point0;
				
				(point.x>point1.x)&&(point.x=point1.x);
				(point.x>point2.x)&&(point.x=point2.x);
				(point.x>point3.x)&&(point.x=point3.x);
				(point.y>point1.y)&&(point.y=point1.y);
				(point.y>point2.y)&&(point.y=point2.y);
				(point.y>point3.y)&&(point.y=point3.y);
				matrix.tx = mc.x - point.x;
				matrix.ty = mc.y - point.y;
				bmpData.draw(mc,matrix);
				return bmpData;
			}


 

你可能感兴趣的:(Flex)