在 Flex 中的 BitmapData 上绘制文本

发布于 2024-11-09 03:14:49 字数 190 浏览 7 评论 0原文

好吧,问题可能很简单,但我无法弄清楚。我有一个图像加载到 BitmapData 中。现在我想从文本输入中获取文本并将其放在 BitmapData 上。基本上,它是在 BitmapData 上绘制文本,并以另一个 BitmapData 形式获取结果,该结果将由原始 BitmapData 以及在其上指定位置绘制的文本组成。在 Flex 中实现这一目标的最佳方法是什么?

Well, the problem may be a simple one but I can't figure it out. I have an image loaded into BitmapData. now I want to take text from a textinput and put it on the BitmapData. Basically it's drawing a text on the BitmapData and get the result as another BitmapData that will consist of the original BitmapData with the text drawn over it on a specified position. What's the best way to achieve this in flex?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

山色无中 2024-11-16 03:14:49

要将文本放入位图中,您可以执行以下操作:

var channelName:TextField = new TextField();
channelName.textColor=0x000000;
channelName.antiAliasType = AntiAliasType.NORMAL;
channelName.alpha=1.0;
var txtFormat:TextFormat = new TextFormat("SansSerif",14,0x000000,true);
channelName.setTextFormat(txtFormat);

var bitmapdata:BitmapData = new BitmapData(
         channelName.width, channelName.height, true, 0x000000);
bitmapdata.draw(channelName);

To put the text inside a bitmap you can do:

var channelName:TextField = new TextField();
channelName.textColor=0x000000;
channelName.antiAliasType = AntiAliasType.NORMAL;
channelName.alpha=1.0;
var txtFormat:TextFormat = new TextFormat("SansSerif",14,0x000000,true);
channelName.setTextFormat(txtFormat);

var bitmapdata:BitmapData = new BitmapData(
         channelName.width, channelName.height, true, 0x000000);
bitmapdata.draw(channelName);
贱贱哒 2024-11-16 03:14:49

你不能根据位图数据来绘制,但你可以从数据中组合它。由于您拥有 BitmapData,因此很容易将其更改为位图 (var bitmap:Bitmap = new Bitmap(bitmapData);),然后将其添加为图像源。

现在舞台上已经有了实际的图像,您现在可以使用您喜欢的内容(文本、标签、文本区域等)在其上方添加文本,然后可以在尺寸上执行 Bitmap.draw图像的像素信息返回到 BitmapData(在 Bitmap.bitmapData 下)。

You can't draw over bitmapdata per say, but you could compose it from the data. Since you have BitmapData, it's easy enough to change it to a bitmap (var bitmap:Bitmap = new Bitmap(bitmapData);) and then add it as source for an image.

Now that you have an actual image on the stage, you can now add text above that using what you like (text, label, textarea, etc) and then you can do a Bitmap.draw over the dimensions of the image to get the pixel information back into a BitmapData (under Bitmap.bitmapData).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文