保存/载入文件状态快速稳健的图像编辑器 [英] Saving/loading document state quickly and robustly for image editor

查看:182
本文介绍了保存/载入文件状态快速稳健的图像编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在找我的,用于存储Android和iPhone手机的一个位图编辑器的状态,做法有些批判。即使是看起来好像没什么问题!响应将是巨大的!

I'm looking for some critique on my approach for storing the state of a bitmap editor for Android and iPhone mobile phones. Even a "Looks fine to me!" response would be great!

在该应用程序中,当前用户文档包含可各自画在几个位层(各也许1024 768像素)。应用程序的基本要求是:

In the application, the current user document contains several bitmap layers (each maybe 1024 by 768 pixels) that can each be painted on. The basic requirements for the application are:


  1. 我需要能够保存和恢复文件的状态。

  1. I need to be able to save and restore the document state.

当用户退出应用程序或获取一个电话,我需要能够快速地将文档保存状态(约2秒之内)。

When the user quits the application or gets a phone call, I need to be able to save the document state quickly (within about 2 seconds).

如果应用程序崩溃,我需要能够恢复状态的文件(这是确定如果用户丢失可能30秒工作虽然)。

If the application crashes, I need to be able to restore the document state (it's OK if the user loses maybe 30 seconds of work though).

有关1,我找不到支持图层所有打开的文件格式。我会用下面的文件结构去储存我的文档:

For 1, I cannot find any open file formats that support layers. I was going to go with the following file structure for storing my document:

document_folder/
  layer1.png
  layer2.png
  ...
  metadata.xml

该层只是存储为.png文件和.xml文件包含数据,如该层是当前可见。因为是由应用程序或文件夹可以存储在一个.zip文件文档文件夹可以被打开。这似乎是对其他应用程序与工作过一个漂亮的简单的格式。

The layers are just stored as .png files and the .xml file contains data such as which layers are currently visible. The document folder can either be opened as is by the application or the folder can be stored in a .zip file. This seems like a nice simple format for other applications to work with too.

除了.png文件,我也将使层保存在其中包含位图未处理的原始像素数据的定制.raw文件格式。我可以在手机上非常快速地保存这些(小于0.5秒)。而.png文件采取第二个或两个

In addition to .png files, I will also allow layers to be saved in a custom .raw file format which contain unprocessed raw pixel data from bitmaps. I can save these very quickly on the phone (<0.5s) whereas .png files take a second or two.

我对快速保存文档的计划是,在启动时,创建一个名为/自动保存的文件夹,并保存所有的层那里.RAW版本。经过几次编辑一个图层上的命令,我会再更新在后台线程该层中的.raw文件。对于稳健性保存时,我会保存层例如layer1_tmp.raw当我确认文件已完全写的,这个文件替换layer1.raw。

My plan for quick-saving the document was, on start-up, to create a folder called /autosave, and save .raw versions of all the layers there. After a few editing commands on one layer, I would then update the .raw file for that layer in a background thread. For robustness when saving, I would save the layer as e.g. layer1_tmp.raw and when I've confirmed the file has been fully written, replace layer1.raw with this file.

如果在使用过程中的应用程序崩溃,我只想重新打开/自动保存文件夹。当应用程序被关闭或用户得到了一个电话,我只需要更新的最后修改层自动保存。当用户想救,我只是将所有的.RAW文件,.png文件,然后压缩的文件夹。

Should the application crash during use, I would just reopen the /autosave folder. When the application is closed or the user gets a phone call, I just have to update the last modified layer to autosave. When the user wants to save, I just convert all the .raw files to .png files and then zip the folder.

你觉得呢?是否有任何明显的缺陷?有没有更简单的方法吗?我是不是重新发明轮子不知何故?谢谢你。

What do you think? Are there any obvious flaws? Is there a simpler way? Am I reinventing the wheel somehow? Thanks.

推荐答案

您的想法souds对我很好:保存层的背景下,当您去。任何用户当前没有被编辑层要排队等待,尽快为他们切换远离它不同的层保存。如果应用程序被中断,你只需要保存当前工作层,像你说的在0.5秒完成它。

Your idea souds good to me: save the layers in the background, as you go. Any layer that the user isn't currently editing should be queued to be saved as soon as they switch away from it to a different layer. If the app is interrupted, you just have to save the current working layer, which as you say can be done in 0.5s.

为什么用PNG格式反正烦?你只需要它,如果将数据导出到另一台机器/系统,对吧?

Why bother with the png format anyway? You only need it if exporting data to another machine/system, right?

这篇关于保存/载入文件状态快速稳健的图像编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆