GDI+ 离屏缓冲滚动
我正在使用 C# GDI+ 创建自定义控件。
快速解释...该控件将在屏幕上显示 500 像素,但可能包含 500000 像素的信息。 因此,虽然我一次只显示 500px,但我显然需要在水平面(左和右)中滚动。 棘手的部分是每个 500px 的位图块都需要一段时间(100 毫秒 - 1000 毫秒)来渲染。
所以我的计划是在内存中维护一个1500px的位图。 即 500px 可见部分和可见区域两侧 500px,并在用户滚动时异步绘制离屏部分。
我想要一些反馈、建议、批评或代码示例来帮助我实现这一目标。 这看起来相当简单,但经过几次初步测试尝试后,事实证明它比人们想象的要困难得多。
谢谢。
I am creating a custom control using C# GDI+.
Quick explanation...the control will be say 500 pixels on screen but will contain perhaps 500000 pixels of information. So although i'm only showing 500px at a time i need to obviously scroll in the horizontal plane (left & right). The tricky part is that each 500px chunk of bitmap takes a while (between 100ms - 1000ms) to render.
So my plan is to maintain a 1500px bitmap in memory. i.e. the 500px visible part and 500px either side of the visible area and draw the off-screen parts asynchronously as the user scrolls.
I would like some feedback, advice, criticism or examples of code to help me achieve this. It seems fairly straight forward but after a few initial test attempts its proving more difficult than one would imagine.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这种方法的有效性取决于用户的移动量等。 如果用户做了小动作,然后停下来考虑新信息,这可能会起作用。 但是,如果用户来回移动,您仍然会遇到问题。
您的应用程序是否适合逐渐提高图像质量 - 即提供快速可用的图像,然后在用户停止考虑时对其进行改进?
The effectiveness of this approach depends on, amongst other things, the amount of moving around the user will do. If the user is making small movement, then stopping to consider the new information, this could work. However, if the user is whizzing back and forth, you'll still have an issue.
Does your application lend itself to gradually improving the quality of the image - i.e. providing a quick usable image and then improving it as the user stops to consider it?
几年前我也遇到过类似的问题。 正如多默提到的,如果您在显示图像块之前对其进行处理,那么您最好先显示一些内容,然后再对其进行改进。 如果您在位图传输原始图像时遇到问题,则说明您的方法有问题。 GDI+ 对像素深度非常挑剔(您需要 32bpp 和 alpha)。
在我们的例子中,我们处理了 500px 的图块,并在可见视图周围填充了一个图块,如果用户滚动到我们处理的区域之外,我们就会用叠加在其上的黑色半透明矩形来剪切原始图像的位。 这些块已排队等待处理。 当我们处理图像块(从中心向外)时,它们半透明的矩形将会消失。
它工作得相当好,反应非常灵敏而且速度非常快。 将原始位图传输到屏幕上的速度非常快,在我们的例子中,处理通常非常接近。 瓷砖变轻的效果实际上非常漂亮。
I had a similar problem a few years back. As dommer mentions, if you're processing chunks of the image before displaying them you're best off showing something and improving it later. If you're having problems blitting the original image, you've got something wrong with your method. GDI+ is very particular about pixel depth (you want 32bpp with alpha).
In our case, we processed in 500px tiles and padded out a tile around the visible view Ff the user scrolled outside the area we'd processed we blitted bits of the original image with a dark semi-opaque rectangle super-imposed on them. These chunks were queued for processing. As we processed chunks of the image (centre-out) they semi-opaque rectangles would disappear.
It worked reasonably well, was very responsive and very fast. It's very fast to blit the original bitmap onto the screen, and in our case the processing was usually very close behind. The effect of the tiles getting lighter was actually quite pretty.
仅绘制可见区域。
构建一个方法
,然后在 OnPaint() 中执行
Draw only the visible area.
Build a method
and then in
OnPaint()
do