生成的用户控件的图形缓存
这个问题专门针对 .net CF,但它应该适用于任何缓慢、陈旧的系统。
我编写了一个自定义 ListPanel 类型对象,其中包含自定义 ListItem 类型对象。每个ListItem包含0-5个不同的图形和1-4组不同的文本(每组文本具有不同的字体或颜色)。每个项目的尺寸 (WxH) 也在 480x14-480x800 之间。ListPanel
对象有一个 Bitmap 类型的缓冲区,它是用于双缓冲的手机屏幕尺寸(通常为 480x800)。每个ListItem还有一个Buffer,它是项目的大小(这是因为ListItem一旦创建就很少改变)。 ListPanel 将其 Buffer 的 Graphics 对象发送到其所有 ListItem,每个 ListItem 使用它来绘制其 Buffer Bitmap。当所有可见项目都使用图形对象绘制完自身后,面板的缓冲区将绘制到屏幕上
。平均列表包含 10-27 个项目。
我有一些关于此缓冲区缓存模式的问题。
首先,保存这么多缓冲区是否过度?在包含 26 个对象的列表中,内存中至少有 28 个位图,这在 .net CF 上是一个很大的空间。如果这已经过头了,那么有什么更好的方法来渲染屏幕(考虑到最坏的情况ListItem会绘制6个图形和4组不同字体的文本)。
另外,还有一些重复出现的图形(存储为嵌入资源或本地复制到输出目录并作为文件读入),我想知道是否最好将这些图像保存在内存中或读取/关闭它们每次使用?
最后,(假设上面的项目)我应该什么时候渲染 ListItem 的缓冲区?我应该在项目的 ctor 中渲染它还是在项目第一次进入显示器时渲染它?在 ctor 中渲染 Buffer 会在创建页面时造成延迟,但在用户滚动时会更加平滑。首次显示时的渲染可能会导致滚动不稳定,但页面加载速度更快,并且某些看不到的项目不需要加载到内存中
任何指导都会很好
This question is specifically for .net CF, but it should apply to any slow, archaic system.
I've written a custom ListPanel type object that holds custom ListItem type objects. Each ListItem contains 0-5 different graphics and 1-4 different sets of text (each set of text has a different font or color). Each item is also between 480x14-480x800 in size (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. Each ListItem also has a Buffer that is the size of the item (this is because the ListItems rarely change once they are created). The ListPanel sends its Buffer's Graphics object to all of its ListItems, and each ListItem uses it to draw its Buffer Bitmap. After all the visible items have drawn themselves with the Graphics Object, the panel's Buffer is drawn to the screen
The average list contains 10-27 items.
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. 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).
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?
Finally, (assuming the items above) when should I render the ListItem's Buffer? Should I render it in the item's ctor or the first time the item enters the display? Rendering the Buffer in the ctor will cause a delay when the page is being created but will be smoother when the user scrolls. 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
Any guidance would be excellent
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你应该看看 这个的接受答案问题。例如,适用于您的情况的一个小片段说:“避免在表单的构造函数中做大量工作 - 将其卸载以进行延迟加载或在后台线程中”
I think you should take a look on the accepted answer for this 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"