最好使用 MFC 进行设计练习
我被告知要设计一个有两种变体的画笔程序,一种使用大量空间和很少的CPU,另一种则相反。
这个想法(正如我被告知的 - 所以不确定)是以某种方式保存屏幕快照而不是保存代表绘画之间增量的异或图(我不知道这意味着什么)。
有人可以建议一种方法或添加相关材料的链接吗?
i was told to design a paintbrush program in 2 variation , one that uses lots of space and little cpu and the other vice versa.
the idea (as i was told- so not sure) is somehow to save the screen snapshots versus saving XOR maps (which i have no idea what it means) who represent the delta between the painting.
can someone suggest a way or add links to related material ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用屏幕截图的明显地方是执行“撤消”命令。简单、占用内存的方法是在每次操作之前拍摄屏幕快照。如果用户点击“撤消”,则可以恢复旧屏幕。
为了节省内存空间,您可以通过将两个屏幕异或在一起来仅保存两个屏幕之间的差异。就其本身而言,这实际上并没有节省任何空间,但它将所有未更改的像素设置为 0。为了节省空间,您需要应用某种压缩。鉴于您通常可以预期相当大的区域全部为零,游程编码可能会快速且有效。对于游程长度编码,您通常会将相同字节的字符串转换为两个字节,第一个字节保存游程长度,第二个字节保存值。例如,一行中的 75 个零将被编码为
75 0
。如果您想更进一步,您可以考虑使用图元文件,而不是保存异或位图。图元文件记录在 Windows GDI 调用级别所采取的操作,因此(例如)如果您在 10、100 处绘制了一个红色的 100x200 矩形,它实际上会记录这一点 - 即,而不是两万像素,它将保存标识符说明要执行哪个 GDI 函数,以及要提供给该函数的参数。在典型情况下,每个执行的“命令”平均可能需要 15-20 个字节左右。同时,它(通常)确实涉及更多计算 - 例如,如果您绘制一个圆,重新运行图元文件需要重新光栅化该圆,而不是仅仅存储它产生的位。
The obvious place to put the screen shots to use would be to implement an "undo" command. The simple, memory-hog method is to take a snapshot of the screen before each action. If the user hits "undo", you can restore the old screen.
To save on memory space, you save only the difference between the two screens, by XORing them together. By itself, this doesn't actually save any space, but it sets all the unchanged pixels to 0. To save space, you'll then need to apply some sort of compression. Given that you can typically expect fairly large areas that are all zero, a run-length encoding will probably be quick and effective. For a run-length encoding, you'll typically turn a string of identical bytes into two bytes, the first holding the length of the run, and the second holding the value. For example, 75 zeros in a row would be encoded as
75 0
.If you wanted to go a step further, instead of saving XORed bitmaps, you could look into using a metafile. A metafile records the actions taken at the level of Windows GDI calls, so (for example) if you drew a red 100x200 rectangle at 10, 100, it would record essentially that -- i.e. instead of the twenty thousand pixels, it would save an identifier saying what GDI function to execute, and the parameters to supply to that function. In a typical case, this might average around 15-20 bytes per "command" executed. At the same time, it does (often) involve more computation -- for example, if you draw a circle, re-running a metafile requires re-rastering the circle instead of just storing the bits it produced.