简体   繁体   English

生成的用户控件的图形缓存

[英]Graphics caching for Generated user controls

This question is specifically for .net CF, but it should apply to any slow, archaic system.这个问题专门针对 .net CF,但它应该适用于任何缓慢的过时系统。

I've written a custom ListPanel type object that holds custom ListItem type objects.我编写了一个自定义 ListPanel 类型 object ,其中包含自定义 ListItem 类型对象。 Each ListItem contains 0-5 different graphics and 1-4 different sets of text (each set of text has a different font or color).每个 ListItem 包含 0-5 个不同的图形和 1-4 个不同的文本集(每组文本具有不同的字体或颜色)。 Each item is also between 480x14-480x800 in size (WxH)每件商品的尺寸也在 480x14-480x800 之间(WxH)

The ListPanel object has a Buffer of type Bitmap which is the size of the phone's screen (usually 480x800) that is used for Double Buffering. ListPanel object 有一个类型为Bitmap的缓冲区,它是用于双缓冲的手机屏幕大小(通常为 480x800)。 Each ListItem also has a Buffer that is the size of the item (this is because the ListItems rarely change once they are created).每个 ListItem 也有一个 Buffer,它是项的大小(这是因为 ListItem 在创建后很少更改)。 The ListPanel sends its Buffer's Graphics object to all of its ListItems, and each ListItem uses it to draw its Buffer Bitmap. ListPanel 将其 Buffer 的 Graphics object 发送到其所有 ListItem,每个 ListItem 使用它来绘制其 Buffer Bitmap。 After all the visible items have drawn themselves with the Graphics Object, the panel's Buffer is drawn to the screen在所有可见项都用 Graphics Object 自己绘制之后,面板的 Buffer 被绘制到屏幕上

The average list contains 10-27 items.平均列表包含 10-27 项。

I have a few questions regarding this buffer caching pattern.关于这个缓冲区缓存模式,我有几个问题。
First, is it over kill to save this many buffers?首先,保存这么多缓冲区是否过度杀戮? In a list with 26 objects, there are at least 28 bitmaps in memory, which on the .net CF is a great amount of space.在一个包含 26 个对象的列表中,memory 中至少有 28 个位图,这在 .net CF 上是很大的空间。 If this is over kill, what would be a better method for rendering the screen (taking into account that the worst case ListItem will draw 6 graphics and 4 sets of text with different fonts).如果这太过分了,那么渲染屏幕的更好方法是什么(考虑到最坏的情况 ListItem 将绘制 6 个图形和 4 组具有不同字体的文本)。

Also, there are a few reoccuring graphics (stored either as an embedded resource or copied locally to the the output directory and read in as a file) and I want to know if it's better to save those images in memory or read/close them for every use?此外,还有一些重复出现的图形(作为嵌入式资源存储或在本地复制到 output 目录并作为文件读入),我想知道将这些图像保存在 memory 中是否更好或读取/关闭它们以每次使用?

Finally, (assuming the items above) when should I render the ListItem's Buffer?最后,(假设上面的项目)我应该什么时候渲染 ListItem 的缓冲区? Should I render it in the item's ctor or the first time the item enters the display?我应该在项目的 ctor 中呈现它还是在项目第一次进入显示器时呈现它? Rendering the Buffer in the ctor will cause a delay when the page is being created but will be smoother when the user scrolls.在 ctor 中渲染 Buffer 会在创建页面时造成延迟,但在用户滚动时会更流畅。 Rendering on first time display can be make for choppy scrolling, but the page loads faster and some items that aren't seen don't need to be loaded into memory首次显示时渲染可能会导致滚动不流畅,但页面加载速度更快,并且某些看不到的项目不需要加载到 memory

Any guidance would be excellent任何指导都会很棒

I think you should take a look on the accepted answer for this SO question .我认为你应该看看这个 SO question的接受答案。 One small fragment that applies to your case for example says: "Avoid doing a lot of work in a Form's ctor - off load it for lazy load or in a background thread"例如,适用于您的案例的一个小片段说:“避免在表单的 ctor 中做大量工作 - 为延迟加载或在后台线程中卸载它”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM