如何借鉴的BitmapData字符串 [英] How to draw a string on BitmapData
问题描述
我怎么可以画弦上的BitmapData,是有什么样Java's Graphics.drawString()?
how can I draw strings onto BitmapData, is there something like Java´s Graphics.drawString()?
推荐答案
在ActionScript中,处理这种最自然的方式,我想,会使用一个容器,如雪碧
和使用绘图它的图形
的对象和/或增加其他显示对象为儿童。然后,你可以把你的快照,当/如果需要的话,得到的像素数据。
In Actionscript, the most natural way of handling this, I think, would be using a container such as Sprite
and drawing using it's graphics
object and / or adding other display objects as children. Then you could take your "snapshot" when / if necessary, to get the pixel data.
有关添加文本,创建一个文本字段
是最简单的选择。
For adding text, creating a TextField
is the simplest option.
总之,你可以写一个小功能,这是否对现有的BitmapData,如果你想要的。这里有一个如何这样的功能可以写一个小品:
Anyway, you could write a little function that does this on an existing BitmapData, if you wanted. Here's a sketch of how such a function could be written:
function drawString(target:BitmapData,text:String,x:Number,y:Number):void {
var tf:TextField = new TextField();
tf.text = text;
var bmd:BitmapData = new BitmapData(tf.width,tf.height);
bmd.draw(tf);
var mat:Matrix = new Matrix();
mat.translate(x,y);
target.draw(bmd,mat);
bmd.dispose();
}
// use
var bitmap:BitmapData = new BitmapData(400,400);
// let's draw something first (whatever is on the stage at this point)
bitmap.draw(stage);
drawString(bitmap,"testing",100,50);
// display the result...
addChild(new Bitmap(bitmap));
这篇关于如何借鉴的BitmapData字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!