收到 Flex Bitmap 或 BitmapData 更改的通知吗?

发布于 2024-09-25 14:22:44 字数 217 浏览 4 评论 0原文

在 Flex 中,如何挂钩位图或位图数据变量,以便每当位图数据发生更改(像素已更改或添加过滤器)时通知函数?

我尝试设置绑定,但不起作用。

一定有办法做到这一点,因为我可以通过“source”属性将 mx:Image 绑定到位图,并且当我修改位图时,显示的图像会一直更新。柔性是如何做到的?它是盲目地在每一帧重绘位图,还是智能地只在位图改变时重绘?如果是这样,它如何知道位图何时发生变化?

In Flex, how does one hook into a bitmap or bitmapdata variable so that a function is notified whenever the bitmap's data has changed (pixel has changed, or filter's been added)?

I tried setting up binding but it doesn't work.

There must be a way to do it, because I can bind an mx:Image to a bitmap via the 'source' attribute, and the displayed image updates all the time when a I modify the bitmap. How does flex do it? Does it blindly redraw the bitmap at every frame, or is it smart and only redraws when the bitmap changes? If so, how does it know when the bitmap changes?

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

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

发布评论

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

评论(1

静若繁花 2024-10-02 14:22:44

这只是一种半有根据的猜测,没有经过任何测试,所以请谨慎对待。

当Flex绑定Image的source属性时,.source的值是BitmapAsset类型。

BitmapAsset 有一个 .bitmapData 属性,它是对相关位图的引用。

我预计 Flex 完成的绑定是针对 .bitmapData 属性的。

我不明白你有什么理由不能这样做。不过,我认为您必须做一些循环工作,因为您必须创建一个 BitmapAsset 实例并用您想要保留选项卡的 BitmapData 填充它打开,然后绑定到 BitmapAsset 对象的 .bitmapData 属性。

假设有一个名为“bitmapData”的变量,它是 BitmapData 的一个实例,我认为以下内容应该有效。

var bitmapAsset:BitmapAsset = new BitmapAsset(bitmapData);

var bitmapDataChangeWatcher:ChangeWatcher = BindingUtils.bindSetter(handleChangeToBitmapData, bitmapAsset, "bitmapData");

private function handleChangeToBitmapData(data:BitmapData):void
{
    // Handle change to the bitmap data
}

This is just sort of a semi-educated guess, with no testing behind it, so take it with some salt.

When Flex binds the source attribute of an Image, the value of .source is of type BitmapAsset.

BitmapAsset has a .bitmapData property, which is a reference to the bitmap in question.

I expect that the binding done by Flex is against that .bitmapData property.

I don't see any reason why you shouldn't be able to do that, too. I think you'd have to do a little circular work, though, as you'd have to create a BitmapAsset instance and populate it with the BitmapData you want to keep tabs on, then bind to the .bitmapData property of the BitmapAsset object.

Assuming a var called 'bitmapData', which is an instance of BitmapData, I think the following should work.

var bitmapAsset:BitmapAsset = new BitmapAsset(bitmapData);

var bitmapDataChangeWatcher:ChangeWatcher = BindingUtils.bindSetter(handleChangeToBitmapData, bitmapAsset, "bitmapData");

private function handleChangeToBitmapData(data:BitmapData):void
{
    // Handle change to the bitmap data
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文