BitmapData merge
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600"
creationComplete="start(event)"
>
<fx:Script>
<![CDATA[
import mx.core.BitmapAsset;
import mx.events.FlexEvent;
[Embed(source="assets/iphone4.jpg")]
private var Iphone:Class;
[Embed(source="assets/cat.jpg")]
private var Cat:Class;
[Embed(source="assets/background.jpg")]
private var BackGround:Class;
protected function start(event:FlexEvent):void
{
var iphone:Bitmap = new Iphone() as Bitmap;
var cat:Bitmap = new Cat() as Bitmap;
var backGround:Bitmap = new BackGround() as Bitmap;
var mixBitMapData:BitmapData = backGround.bitmapData;
var catX:Number = (backGround.width - cat.width)/2;
var catY:Number = (backGround.height - cat.height)/2;
//合併背景與貓
mixBitMapData.merge(cat.bitmapData , cat.bitmapData.rect ,new Point(catX,catY),0x100,0x100,0x100,0x100);
var iphoneX:Number = catX + 110;
var iphoneY:Number = catY + 50;
//0x100這些是RGBA通道的複製值,0x100是完全,以下會混合
mixBitMapData.merge(iphone.bitmapData , iphone.bitmapData.rect , new Point(iphoneX , iphoneY),0x100,0x100,0x100,0x100);
catUic.width = cat.width;
catUic.height = cat.height;
catUic.addChild(cat);
iphoneUic.width = iphone.width;
iphoneUic.height = iphone.height;
iphoneUic.addChild(iphone);
uic.addChild(backGround);
}
]]>
</fx:Script>
<s:VGroup width="100%" height="100%">
<s:HGroup id="box">
<mx:UIComponent id="catUic"/>
<mx:UIComponent id="iphoneUic"/>
</s:HGroup>
<mx:UIComponent id="uic"/>
</s:VGroup>
</s:Application>
沒有留言:
張貼留言