开发工具:
文件大小: 29kb
下载次数: 0
上传时间: 2011-12-01
详细说明: 实现AS截屏不能少的库。这个库需要与as3corelib.swc一起使用。 下面是代码部分: package { import aether.utils.ScreenCapture; import com.adobe.images.JPGEncoder; import flash.display.BitmapData; import flash.display.Sprite; import flash.events.MouseEvent; import flash.geom.Rectangle; import flash.net.FileReference; import flash.utils.ByteArray; [SWF(width=800,height=600,backgroundColor=0xffffff)] public class PrintScreen extends Sprite { private var bitmapData:BitmapData; public function PrintScreen() { //画了一些随机的矢量图 graphics .lineStyle(1); graphics.drawRect(0,0,100,100); for(var i:int=0;i<30;i++){ var tempx:Number=Math.random()*400; var tempy:Number=Math.random()*300; var color:Number=0xff0000*Math.random(); graphics.lineStyle(1,color); graphics.lineTo(tempx,tempy); graphics.endFill(); } //定义截屏的区域,并保存在bitmapData中 //false是位图是否有transparent项 var region:Rectangle= new Rectangle(0, 0, 100, 100); bitmapData= ScreenCapture.capture(stage,false, region); // 一个按钮,用于启动截屏 var saveBtn:MyButton=new MyButton("save",50,30); saveBtn.x=700; saveBtn.y=150; addChild(saveBtn); saveBtn.addEventListener(MouseEvent.CLICK,save); } private function save(e:MouseEvent):void{ var encoder:JPGEncoder = new JPGEncoder(80); //80是quality var bytes:ByteArray= encoder.encode(bitmapData); var fr:FileReference = new FileReference(); fr.save(bytes, "screen.jpg"); } } } MyButton类 package { import flash.display.* import flash.text.*; import flash.filters.DropShadowFilter; public class MyButton extends SimpleButton { // The text to appear on the button private var _text:String; // Save the width and height of the rectangle private var _width:Number; private var _height:Number; public function MyButton( text:String, width:Number, height:Number ) { // Save the values to use them to create the button states _text = text; _width = width; _height = height; // Create the button states based on width, height, and text value upState = createUpState(); overState = createOverState(); downState = createDownState(); hitTestState = upState; } // Create the display object for the button's up state private function createUpState():Sprite { var sprite:Sprite = new Sprite(); var background:Shape = createdColoredRectangle( 0xcccccc ); var textField:TextField = createTextField( false ); sprite.addChild( background ); sprite.addChild( textField ); return sprite; } // Create the display object for the button's up state private function createOverState():Sprite { var sprite:Sprite = new Sprite(); var background:Shape = createdColoredRectangle( 0xff0000 ); var textField:TextField = createTextField( false ); sprite.addChild( background ); sprite.addChild( textField ); return sprite; } // Create the display object for the button's down state private function createDownState():Sprite { var sprite:Sprite = new Sprite(); var background:Shape = createdColoredRectangle( 0xCCCCCC ); var textField:TextField = createTextField( true ); sprite.addChild( background ); sprite.addChild( textField ); return sprite; } // Create a rounded rectangle with a specific fill color private function createdColoredRectangle( color:uint ):Shape { var rect:Shape = new Shape(); rect.graphics.lineStyle( 1, 0x000000 ); rect.graphics.beginFill( color ); rect.graphics.drawRect( 0, 0, _width, _height); rect.graphics.endFill(); rect.filters = [ new DropShadowFilter( 2 ) ]; return rect; } // Create the text field to display the text of the button private function createTextField( downState:Boolean ):TextField { var textField:TextField = new TextField(); textField.text = _text; textField.width = _width; // Center the text horizontally var format:TextFormat = new TextFormat(); format.align = TextFormatAlign.CENTER; textField.setTextFormat( format ); // Center the text vertically textField.y = ( _height - textField.textHeight ) / 2; textField.y -= 2; // Subtract 2 pixels to adjust for offset // The down state places the text down and to the right // further than the other states if ( downState ) { textField.x += 1; textField.y += 1; } return textField; } } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.