Pergunta

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.

Foi útil?

Solução

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.

Outras dicas

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?

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top