を切り出して塗りつぶしを作成するには、マスクとして、ダイナミックテキストフィールドを使用していることを実行する方法です。トリックは、テキストフィールドのアルファチャンネルを反転させることです。 このクラスは透明なビットマップデータを作成します。 次に、テキストフィールドを作成します。 次に、テキストフィールドを描画するビットマップデータを作成します。 テキストを描画し、テキストのアルファチャンネルを反転させて、以前に表示されたものを切り捨てます。 テキストbitmapdataのアルファチャンネルをカラーbitmapdatに適用します。その結果、色からテキストが切り取られます。最後に 。ビットマップを追加して私たちの作業を示します。 (コロンがテキストを切り取っていることがわかります) これをマシン上で実行すると、アニメーションエイリアシングのないデフォルトのフォントが使用されるため、ジャギーが発生します。しかし、あなたは簡単に独自のフォントで独自のテキストフィールドを作成し、その代わりに描画することができます。その後、滑らかに見えます。
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BitmapDataChannel;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.TextEvent;
import flash.geom.ColorTransform;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.text.TextField;
/**
* ...
* @author Zachary Foley
*/
public class Main extends Sprite
{
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
// Make a red square bitmapdata that allows transparency.
var color:BitmapData = new BitmapData(400, 400, true, 0xFF990000);
var word:TextField = new TextField;
word.text = "HELLO MASK";
var textMask:BitmapData = new BitmapData(word.width, word.height, true, 0x00000000);
textMask.draw(word);
textMask = invert(textMask);
var colorHolder:Bitmap = new Bitmap(color);
addChild(colorHolder);
color.copyChannel(textMask, textMask.rect, new Point(0, 0), BitmapDataChannel.RED, BitmapDataChannel.ALPHA);
}
private function invert(oldBmp:BitmapData):BitmapData {
var source:BitmapData = oldBmp;
var destination_bitmap:BitmapData = source.clone();
var rectan:Rectangle = new Rectangle(0, 0, source.width, source.height);
// Replace all transparent pixels with a solid color
destination_bitmap.threshold(source, rectan, new Point(), "==", 0x00000000,0xFFFF0000);
// Replace all the pixels greater than 0xf1f1f1 by transparent pixels
destination_bitmap.threshold(source, rectan, new Point(), "==", 0xff656565,0x0000FF00);
return destination_bitmap;
}
}
}