AS3:ByteArray 和 BitmapData

发布于 2024-07-27 19:34:29 字数 586 浏览 9 评论 0 原文

我正在做一个简单的测试。 我想将 BitmapData 写入 ByteArray。 我正在尝试使用 writeObject() 和 readObject() 来做到这一点。 读取对象似乎无法理解 BitmapData。

var byteArray : ByteArray = new ByteArray();
var _cache : BitmapData = new BitmapData( 640, 480, true, 0x000000 );
var _blank : BitmapData = new BitmapData( 640, 480, true, 0x000000 );

byteArray.writeObject( _blank );
byteArray.position = 0;
_cache = byteArray.readObject() as BitmapData;
trace( _cache ); // Traces null

谁能帮我解决这个问题吗? 我无法理解 readObject(); 出了什么问题。

我知道我可以执行 getPixels() 和 setPixels() 操作,但我想将对象视为此处的对象。

I'm doing a simple test. I want to write BitmapData into a ByteArray. I'm trying to do this with writeObject() and readObject(). Read object seems to have trouble making sense of the BitmapData.

var byteArray : ByteArray = new ByteArray();
var _cache : BitmapData = new BitmapData( 640, 480, true, 0x000000 );
var _blank : BitmapData = new BitmapData( 640, 480, true, 0x000000 );

byteArray.writeObject( _blank );
byteArray.position = 0;
_cache = byteArray.readObject() as BitmapData;
trace( _cache ); // Traces null

Can anyone clear this up for me? I can't make sense of what's going wrong with readObject();

I know I can do this getPixels() and setPixels(), but I'd like to treat the object as an object here.

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

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

发布评论

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

评论(1

萌︼了一个春 2024-08-03 19:34:30

您应该使用 BitmapData::getPixelsBitmapData::setPixels ...将类实例写入 ByteArray 因此永远不会完全按预期工作...尝试使用 Sprites .. :) ...这主要是因为默认实现仅将对象的属性写入 IDataOutputByteArraySocket) ...从这个意义上来说,像素不是 BitmapData 的属性...BitmapData 只是一个 ActionScript 包装器,它向某些内部公开一个接口flash播放器数据结构...

您应该为BitmapData编写一个适配器 ,实现 IExternalizable ,这样你就可以控制发生的事情......本质上,你只需要读/写尺寸,以及实际的像素有效负载......也许是透明标志......记住使用 registerClassAlias ...

greetz

后退2dos

you should use BitmapData::getPixels and BitmapData::setPixels ... writing class instances to a ByteArray as such never completely works as expected ... try with Sprites ... :) ... this is mostly due to the fact, that the default implementation somehow only writes an object's property to the IDataOutput (ByteArray or Socket) ... the pixels are not a property of the BitmapData in that sense ... the BitmapData is just an ActionScript wrapper, that exposes an interface to some internal flash player data structure ...

you should write an adapter for BitmapData, that implements IExternalizable, so that you have control, over what happens ... essentially, you will only need to read/write the dimensions, and the actual pixel payload ... maybe the transparent-flag ... remember to use registerClassAlias ...

greetz

back2dos

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