import com.adobe.images.JPGEncoder;

import com.adobe.images.JPGEncoder;

如果flash编译出错,可以到

https://github.com/mikechambers/as3corelib/downloads

下载类库,版本要和flash想对应,可以通过flash的“帮助》关于”菜单查看自己的flash是什么版本。

 

下载完,把压缩包中的corelib.swc放到如下目录(根据自己计算机的情况而定)

D:/Program Files/Adobe/Adobe Flash CS3/zh_cn/Configuration/ActionScript 3.0/Classes

 

再次编译自己做的flash就可以通过了。

 

 

学习文章参见

 

ActionScript 3 Jpeg Encoder实例:保存flash中的图片 - [flash开发]

http://madinsect.blogbus.com/logs/24042051.html

实现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; } } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值