尝试得到控件的快照,就像位图信息,然后用来做效果。查查文档,真的可以。BitmapData 有一个draw()方法便可以做到,它可以像照相机一样对控件进行拍照,得到控件的位图信息。
draw() 方法的声明:
public function draw(source:IBitmapDrawable,
matrix:Matrix = null,
colorTransform:ColorTransform = null,
blendMode:String = null,
clipRect:Rectangle = null,
smoothing:Boolean = false):void
关注前面两个参数,source 参数是目标控件,matrix 参数决定怎样来拍照。matrix 是一个矩阵,不同的设置,得到的位图信息就不相同。见下图:
还没玩到那么花哨,现在只用到它的tx,ty。
图中是一个3x3的矩阵,其实只能用前两行的6个。
得到位图信息后,便可以为所欲为了,哈。
用这个方法做了个效果,与大家分享。
点击下方的按钮便可以将Panel拆来拆去了。
代码不多,直接贴出来了,同时思考能否用这种方法做出百叶窗的效果:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()"
verticalScrollPolicy="off" horizontalScrollPolicy="off" width="500" height="500">
<mx:Script>
<![CDATA[
import mx.events.EffectEvent;
import mx.effects.Move;
import mx.effects.Parallel;
import mx.states.AddChild;
import mx.controls.Image;
private var bitmapData:BitmapData = null;
private var matrix1:Matrix = null;
private var matrix2:Matrix = null;
private var matrix3:Matrix = null;
private var matrix4:Matrix = null;
internal var image1:Image=null,image2:Image=null,image3:Image=null,image4:Image=null;
internal var isPanelShow:Boolean = true;
internal function init():void{
matrix1 = new Matrix(1,0,0,1,0,0);
matrix2 = new Matrix(1,0,0,1,-panel.width/2,0);
matrix3 = new Matrix(1,0,0,1,0,-panel.height/2);
matrix4 = new Matrix(1,0,0,1,-panel.width/2,-panel.height/2);
image1 = new Image();
image2 = new Image();
image3 = new Image();
image4 = new Image();
addChild( initImageFromMatrix( image1 ,matrix1 ));
addChild( initImageFromMatrix( image2 ,matrix2 ));
addChild( initImageFromMatrix( image3 ,matrix3 ));
addChild( initImageFromMatrix( image4 ,matrix4 ));
image1.width = image2.width = image3.width = image4.width = panel.width/2;
image1.height = image2.height = image3.height = image4.height = panel.height/2;
image1.visible = image2.visible = image3.visible = image4.visible = false;
image1.scaleContent = image2.scaleContent = image3.scaleContent = image4.scaleContent = false;
setChildrenTop([image1,image2,image3,image4]);
panel.visible = true;
btnShow.addEventListener(MouseEvent.CLICK,onClickShowOrHide);
}
internal function initImageFromMatrix(image:Image, matrix:Matrix):Image{
if(image == null) return null;
image.load( new Bitmap( getBitmapDataFromMatrix( matrix ) ) );
trace(image);
return image;
}
internal function setChildrenTop( array:Array ):void{
if(!array)return;
var len:int = array.length;
if(len == 0 ) return;
var displayObject:DisplayObject = null;
for(var i:int = 0; i <len ; ++i){
displayObject = array[i] as DisplayObject;
setChildIndex(displayObject ,numChildren-1 );
}
}
internal function getBitmapDataFromMatrix(matrix:Matrix):BitmapData{
var bitmapData:BitmapData = new BitmapData(panel.width/2,panel.height/2);
bitmapData.draw(panel,matrix);
return bitmapData;
}
internal function onClickShowOrHide( e:MouseEvent ):void{
if(isPanelShow == false){
createEffectsShow();
}else{
createEffectsHide();
}
btnShow.enabled = false;
}
internal function createEffectsHide():void{
getCurrentBitmapData();
image1.visible = image2.visible =image3.visible=image4.visible= true;
panel.visible = false;
var parallel:Parallel = new Parallel();
var move1:Move = new Move(image1);
move1.xTo = 0 - panel.width/2;
move1.xFrom = panel.x;
move1.yTo = 0 - panel.height/2;
move1.yFrom = panel.y;
var move2:Move = new Move(image2);
move2.xTo = width;
move2.xFrom = panel.x + panel.width/2;
move2.yTo = 0 - panel.height/2;
move2.yFrom = panel.y;
var move3:Move = new Move(image3);
move3.xTo = 0 - panel.width/2;
move3.xFrom = panel.x;
move3.yTo = height;
move3.yFrom = panel.y + panel.height/2;
var move4:Move = new Move(image4);
move4.xTo = width;
move4.xFrom = panel.x + panel.width/2;
move4.yTo = height;
move4.yFrom = panel.y + panel.height/2;
parallel.children = [move1,move2,move3,move4];
parallel.addEventListener(EffectEvent.EFFECT_END, onHideEffectEnd);
parallel.duration = 1000;
parallel.play();
}
internal function getCurrentBitmapData():void{
initImageFromMatrix( image1 ,matrix1 );
initImageFromMatrix( image2 ,matrix2 );
initImageFromMatrix( image3 ,matrix3 );
initImageFromMatrix( image4 ,matrix4 );
}
internal function createEffectsShow():void{
getCurrentBitmapData();
image1.visible = image2.visible =image3.visible=image4.visible= true;
panel.visible = false;
var parallel:Parallel = new Parallel();
var move1:Move = new Move(image1);
move1.xFrom = 0 - panel.width/2;
move1.xTo = panel.x;
move1.yFrom = 0 - panel.height/2;
move1.yTo = panel.y;
var move2:Move = new Move(image2);
move2.xFrom = width;
move2.xTo = panel.x + panel.width/2;
move2.yFrom = 0 - panel.height/2;
move2.yTo = panel.y;
var move3:Move = new Move(image3);
move3.xFrom = 0 - panel.width/2;
move3.xTo = panel.x;
move3.yFrom = height;
move3.yTo = panel.y + panel.height/2;
var move4:Move = new Move(image4);
move4.xFrom = width;
move4.xTo = panel.x + panel.width/2;
move4.yFrom = height;
move4.yTo = panel.y + panel.height/2;
parallel.children = [move1,move2,move3,move4];
parallel.addEventListener(EffectEvent.EFFECT_END, onShowEffectEnd);
parallel.duration = 1000;
parallel.play();
}
internal function onShowEffectEnd(e:EffectEvent):void{
image1.visible = image2.visible = image3.visible= image4.visible = false;
panel.visible = true;
btnShow.enabled = true;
btnShow.label = "点击隐藏Panel";
isPanelShow = true;
}
internal function onHideEffectEnd(e:EffectEvent):void{
image1.visible = image2.visible = image3.visible= image4.visible = false;
panel.visible = false;
btnShow.enabled = true;
isPanelShow = false;
btnShow.label = "点击显示Panel";
}
]]>
</mx:Script>
<mx:Panel id="panel" x="125" y="138" width="250" height="200" layout="absolute">
<mx:Button x="26" y="119" label="加入GCD" height="31" width="83"/>
<mx:Button x="140" y="119" label="取 消" height="31" width="86"/>
<mx:TextInput x="69" y="10"/>
<mx:TextInput x="69" y="46"/>
<mx:Label x="13" y="14" text="姓什么:"/>
<mx:Label x="14" y="49" text="叫什么:"/>
<mx:Label x="13" y="91" text="男的女的:"/>
<mx:RadioButton x="101" y="89" label="男"/>
<mx:RadioButton x="162" y="89" label="女"/>
</mx:Panel>
<mx:Button id="btnShow" x="173" y="368" label="点击隐藏Panel" height="37" width="154"/>
<mx:Style>
Application {
backgroundColor: #a7a75e;
backgroundGradientColors: #999966, #585821;
backgroundGradientAlphas: 0.52, 0.46;
themeColor: #9d9d24;
color: #000000;
fontSize:12;
}
Panel {
borderColor: #893654;
borderAlpha: 0.92;
borderThicknessLeft: 6;
borderThicknessTop: 1;
borderThicknessBottom: 9;
borderThicknessRight: 5;
roundedBottomCorners: false;
cornerRadius: 0;
headerHeight: 26;
backgroundAlpha: 0.68;
highlightAlphas: 0.58, 0.16;
headerColors: #744848, #5a1f1f;
footerColors: #6c3131, #682b2b;
backgroundColor: #4f2929;
shadowDistance: 6;
dropShadowColor: #4b3737;
}
Button {
cornerRadius: 0;
textIndent: 0;
fillAlphas: 0.39, 0.81, 0.42, 0.41;
fillColors: #181a47, #120e39, #1d154f, #110f3e;
color: #1f070c;
textRollOverColor: #3e0931;
textSelectedColor: #470e36;
borderColor: #080808;
themeColor: #161352;
}
</mx:Style>
</mx:Application>
分享到:
相关推荐
BitmapData类实例 运用噪声制作一些好的效果 源码
ActionScript 3 BitmapData 的例子 有助于你了解ActionScript 3位图!
最近要转开发平台,正研究C#。C#好是好,不过处理图片时一个像素一个像素的操作像素不是一般的慢。其实Delphi也一样,但好在Delphi的Bitmap类提供了ScanLines,可以一行一...经过一番搜索,终于发现了C# BitmapData类。
想把 draw方法弄明白
NULL 博文链接:https://as3.iteye.com/blog/964080
delphi 找图找色 BitmapData.pas 使用方法请到原作者yeye55的blog查看, http://yeye55blog.blog.163.com/blog/static/19724102120111043252016/
EaselJS的位图数据EaselJS的BitmapData将AS3(例如BitmapData)添加到EaselJS。例1 // create BitmapData by HTMLImageElement_bmd01 = new createjs.BitmapData(HTMLImageElement);_bitmap01 = new createjs.Bitmap...
位图数据处理,主要用于位图的找图找色:BitmapData.pas 實現按键精靈的功能:kbKernel.pas
综合以上特性,我们可以使用Bitmap将矢量图动画缓存为位图动画,多个相同的对象共用同一份BitmapData数据,这样既可以大幅降低cpu占用,又可以节省内存,同时还避免了直接在库里面使用图片而造成flash文件变大的...
一个delphi下用于快速找图找色的单元,很好用!!! 原下载地址已经全部失效,在这里分享给大家,希望使用delphi的朋友能够喜欢。
NULL 博文链接:https://kinglong.iteye.com/blog/1609379
as2.0 模拟火焰 import flash.display.*...var blueSpot: BitmapData = new BitmapData( clipBounds.xMax, clipBounds.yMax, true, 0 ) blueSpot.draw( blueSpotClip, new Matrix() ) blueSpotClip.removeMovieClip()
使用新的Pixel Bender技术来创建用于位图滤镜的ActionScript着色器、混合模式和填充模式; 在图像、文本和视频上应用动态的、可复用的效果,同时包括网络摄像头和麦克风的可视化; 结合开源的效果和动画类库,使得...
王者找图对比程序,delphi制作,设定一个图,找另一个图上是否有这个图!
Flex RIA AS3网页游戏 BitmapData CopyPixel用法.rar
通过 BitmapData.threshold 的方法来实现对图片的特殊效果的展示。附源文件。
将Bitmap转成byte[],进行保存,用到时再取出byte[],转化成Bitmap,进行显示
所以通过 BitmapData 的颜色方式来保存只能保存较小的位图。所以通过鼠标轨迹的方式保存涂鸦成了主流。 此涂鸦板在涂鸦之后会自动将涂鸦保存在本地,并且可以撤消上一步操作。涂鸦画线功能我是直接从FLASH帮助文件...
CreateJS 的 BitmapData 的 TypeScript 定义。 这是一个定义文件,用于将 BitmapData 类用于 CreateJS 和 TypeScript。 如何使用 是定义文件体。 请从 TypeScript 程序中读取并使用它。 请注意,单独使用此文件是...