撤消对位图的更改? [英] Undo changes to Bitmap?

查看:68
本文介绍了撤消对位图的更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您是否有任何有效的解决方案来撤消对位图的更改?



以下是我所知道的解决方案:



1.在任何更改之前保存完整的Bitmap副本。

2.只保存原始Bitmap和更改后的Bitmap之间的差异,差异存储为某个结构的数组包括有关点位置和点颜色的信息(argb)。



3.我正在寻找。



我也知道Graphics.Save()和Graphics.Restore()方法,但是我不太清楚这些方法可以为我做些什么,我知道它们只能帮助我们保存和恢复对Graphics对象进行的转换。这意味着像素的改变不能以这种方式撤消,不是吗?





你能不能给我任何东西这个有效的解决方案?如果没有解决方案,我将在我的列表中寻找第二个解决方案。谢谢!



VipHaLong

Do you have any efficient solution to undo changes to a Bitmap?

Here are solutions I know:

1. Save exactly a copy of the Bitmap before any change.
2. Save just the difference between the original Bitmap and the changed Bitmap, the difference is stored as an array of some structure including information about point location and point color (argb).

3. I''m seeking for.

I also know of Graphics.Save() and Graphics.Restore() methods, but I don''t know much clear about what these methods can do for me, all I know is they can help us save and restore only transformations done to a Graphics object. That means changes to pixels can''t be undone this way, doesn''t it?


Could you please give me any efficient solution for this? If there is no solution, I will go for the second solution in my list. Thank you!

VipHaLong

推荐答案

如果你需要能够执行一次撤消一系列的变化,保存整个图像就足够了。如果变化很多,它甚至可以是最佳解决方案。 (由于您需要存储坐标以及旧的argb,因此更改像素的列表不太紧凑。)



如果你能够撤消每个原子的魔杖改变,保存每个中间位图可能是矫枉过正,积累差异变得更有吸引力。一个通用的解决方案可以是交替全图像保存(当大部分图像被修改时)和节省差异。



大部分时间,变化是不可逆转的。覆盖像素时,无法检索其先前的值。例如,如果应用平滑滤镜,则无法将其反转以恢复精确原始滤镜。这似乎意味着如果发生大的变化,你需要保留大量信息。



但是有一个解决方法诀窍:你可以保持间隔恢复点加上它们之间的各个变换列表。然后,不是从当前状态向后工作,而是从前一个还原点开始向前工作,然后重新应用直接变换。这样,您可以将存储空间换成运行时间(变换列表非常紧凑)。



示例:

If you need to be able to perform a single Undo after a series of changes, saving the whole image is good enough. It can even be the best solution if changes are numerous. (A list of changed pixels is less compact as you need to store the coordinates as well as the old argb).

If you wand to be able to Undo every atomic change, saving every intermediate bitmap is probably overkill and accumulating the differences becomes more attractive. A one-size-fits-all solution can be to alternate full image saving (when most of the image is modified) and differences saving.

Most of the time, changes are irreversible. When you overwrite a pixel, you can''t retrieve its previous value. For instance, if you apply a smoothing filter, you can''t invert it to restore the exact original. That seems to imply that in case of large changes you need to keep a lot of information.

But there is a workaround trick: you can keep spaced restore points plus the list of individual transforms between them. Then, rather than working backward from the current state, you will work forward from the previous restore point, and re-apply the direct transform. This way, you trade storage for running-time (the transform list being extremely compact).

Example:
Original > Smooth > Fill a Rectangle > Invert



连续撤销'是通过重新计算获得的:


Successive Undo''s are obtained by recomputing:

Original > Smooth > Fill a Rectangle




Original > Smooth




Original



重新计算时,您可以缓存所有中间图像,以便全部两个恢复点之间的撤消'和重做'很快。


While recomputing, you can cache all intermediate images so that all Undo''s and Redo''s between two restore points are fast.


这篇关于撤消对位图的更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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