将位图存储为临时文件以实现撤消和重做功能是个好主意吗?

发布于 2024-10-01 09:20:08 字数 120 浏览 4 评论 0原文

在我的项目中,我对位图的像素进行了重大更改,并且我想向该项目添加撤消重做功能。由于在虚拟机内存上保存多个位图不是一个好主意,我认为我唯一的选择是将历史记录(位图)存储为临时文件在开始实施之前,我想确保我在这里做的事情并不愚蠢。

In my project i am making big changes on pixels of a bitmap and i want to add undo redo feature to this project.Sincesaving several bitmaps on VM's memory is not a good idea i thought my only choice is storing history(bitmaps) as temp files.Before starting to implement i want to be sure i am doing something not stupid here.

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

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

发布评论

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

评论(3

孤星 2024-10-08 09:20:08

取决于处理能力和您想要维护的撤消历史记录的长度。如果您可以以合理的速度应用转换,那么您只需保留位图 x 操作的副本,并且在撤消时只需对其应用最后的 x-1 转换。

Depends on the processing power and the length of undo history you want to maintain. If you can apply the transformations with reasonable speed then you can just keep a copy of a bitmap x operations back and in case of an undo just apply the last x-1 transformations to it.

花间憩 2024-10-08 09:20:08

您需要以多快的速度进行撤消?请记住:记忆比任何东西都快。

您需要多少个位图才能返回并撤消?如果很多,那么临时文件可能是最好的。

如果他们关闭应用程序并稍后再回来(或者应用程序被终止以释放内存)怎么办?撤销这些操作有多重要?如果它很重要,那么您需要将它们保存到磁盘。

图像有多大?这也可能影响你决定能记住多少。

也许甚至考虑两者兼而有之?将最新的内容保留在内存中并将其和所有其他内容保存到磁盘吗?

How fast do you need the undo to happen? Remember: memory is faster than anything else.

How many bitmaps do you need to be able to go back and undo? If it's a lot, then yes, temporary files might be best.

What if they close the app and come back later (or the app is killed to free memory)? How important is it to get to those undos? If it is important, then you need to save them to disk.

How big are the images? That could also factor in your decision of how many you could in memory.

Perhaps even consider some of both? Keep the most recent in memory and save it and all others to disk?

探春 2024-10-08 09:20:08

无论堆上是否有空间,将撤消状态存储在持久存储(而不是临时文件)中是唯一的选择。用户可以离开您的应用程序,此时您的进程可以被终止。返回后,您需要以上次看到的相同状态重新启动应用程序。你自己堆里的任何东西都将不再存在;您不能在 onSaveInstanceState() 中将大位图放入 Bundle 中。所以你需要将它们放入持久存储中。

只需确保在执行此操作时不会阻塞 UI - 通过更新 UI 异步写入新状态。

Whether or not you have room on the heap, storing the undo state in your persistent storage (not temp files) is your only option. The user can leave your app, at which point your process can be killed. Upon returning, you need to restart your app with the same state they last saw. Anything you had in your own heap will no longer be there; you can not put big bitmaps in the Bundle in onSaveInstanceState(). So you need to put them in persistent storage.

Just make sure you don't block the UI while doing so -- write a new state asynchronously from updating the UI.

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