NSImage 的动画在使用 NSKeyedArchiver 存档后丢失

发布于 2024-08-21 04:24:46 字数 513 浏览 5 评论 0原文

以下情况:

我有一个 NSObject 子类对象的实例。它的属性之一是 NSImage。实例化对象后,我使用 NSKeyedArchiver 将其转换为数据,通过网络发送它,使用 NSKeyedUnarchiver 取消存档,并在 NSImageView 中显示图像(设置动画:是)。到这里为止都没有问题。图像可以在另一台机器上显示。现在的问题是:
如果我发送 gif 动画,它不会有动画效果。我不知道为什么......有什么想法为什么动画不出现吗?谢谢你!

更新

如果我在存档之前打开动画图像,NSImageView 会对其进行动画处理。问题可能是存档...

更新2

我测试了整个工作流程,没有通过网络发送数据,只是再次存档和取消存档。正如我怀疑的那样,这是 NSKeyed(Un)Archiver 的问题。
动画丢失了。 但是如何防止这种情况发生呢?

Following situation:

I have an instance of my NSObject sublcassed object. One of it's properties is a NSImage. After instanciating the object I convert it with NSKeyedArchiver to data, send it over the network, unarchive it with NSKeyedUnarchiver and display the image in a NSImageView (setAnimates: YES). Until here there are no problems. The image can be displayed on the other machine. Now the problem:
If I send an animated gif, it won't animate. I don't know why... Any ideas why the animation stays away? Thank you!

UPDATE

If I open the animated image before archiving it the NSImageView animates it. The problem is maybe the archiving...

UPDATE 2

I tested the whole workflow without sending the data over the network, just archiving and unarchiving it again. As I suspected it is a problem with NSKeyed(Un)Archiver.
The animation gets lost. But what to do to prevent this?

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

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

发布评论

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

评论(2

花海 2024-08-28 04:24:46

我只是归档原始图像数据,而不是图像实例。

I would simply archive the original image data, instead of the image instance.

千纸鹤 2024-08-28 04:24:46

默认情况下,NSImage 不保留原始源图像数据。可能发生的情况是 NSImage 仅存档一帧的静态位图并丢弃原始内容。

如果您调用[yourNSImageObject setDataRetained:YES],那么NSImage应该保留原始数据(在本例中为动画GIF)。我建议您在首次创建映像时尝试执行此操作,然后查看存档/取消存档时会发生什么。

By default, NSImage doesn't retain the original source image data. What's probably happening is that NSImage is archiving the static bitmap of one frame only and discarding the original content.

If you call [yourNSImageObject setDataRetained:YES] then the NSImage should hang on to the original data (in this case, the animated GIF). I'd suggest you try doing this when the image is first created, and then see what happens when it's archived/unarchived.

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