影响使用 GDI 渲染图像的时间的因素
这是我上一个问题加速图像处理的后续问题,
如果我应该修改的话,抱歉以某种方式提出问题,而不是开始新的问题。
我尝试了各种不同的方法来加快屏幕上图像的绘制速度。
我认为压缩图像直到它变小会有效果。然而,虽然这可能会节省对象的内存,但我认为它对绘制所需的时间没有任何影响。我尝试将图像转换为 jpeg 并使用 100% 压缩。然而,虽然这会创建块状图像,但它不会影响绘图时间。我现在认为这是因为渲染的像素数没有因此而改变,
我尝试将调色板减少到 256 色。这使得尺寸更小,因为它每个像素使用更少的字节,但似乎不影响在屏幕上绘图。我原以为减少 GDI+ 必须处理的每个像素的字节数可能会节省一些时间,但到目前为止我认为这还不够。
那么我是在浪费时间研究压缩和调色板吗?
我假设所花费的时间将受到要绘制的像素数量(宽度 x 高度)的影响,并且我已经调整了图像大小以匹配屏幕上显示的像素大小。我认为这是确实产生影响的一件事......
我已经研究了如何停止图像的自动缩放 - 我的调整大小是否会停止,或者图像在渲染时仍然可以自动缩放?
我想知道是否可以使用 p/Invoke 或其他 API 调用(我承认我不太理解)来替换 DrawImage 调用。
This is a follow on to my previous question Speeding Up Image Handling
Apologies if I should have amended that question in some way rather than starting a new one.
I have tried all sorts of different things to speed up the drawing of an image on screen.
I thought that compressing the image until it is smaller would have an effect. However while this might save memory for the object I do not think it has any effect on how long it takes to draw. I tried converting the image to jpeg and using 100% compression. However while this creates a blocky image it does not affect the drawing time. I now think this is because the number of pixels that get rendered is not changed by this
I tried reducing the color palette to 256 colors. This makes the size smaller since it uses less bytes per pixel but does not seem to affect drawing on screen. I had thought that reducing the bytes per pixel GDI+ has to handle might save some time but it is not enough for me to see so far.
So am I wasting my time looking at compression and palette?
I assume that time taken will be affected by the number of pixels to be drawn (width x height) and I have resized the image to match the pixel size as displayed on screen. I think this is the one thing that does have an effect....
I have looked at how to stop autoscaling of the image - does my resize stop that or can the image still be autoscaled when it is rendered?
I am wondering if I can replace the DrawImage call with something using p/Invoke or other API call (which I admit I don't really understand).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
Bitblt
P/Invoke,它直接复制图像数据。它确实需要一些初始化才能将图像数据转换为显示设备可以理解的内容,但这种复制操作速度快如闪电。顺便说一句,如果您想知道DrawImage
中到底发生了什么,请使用 ILSpy 或 Reflector.NET 等工具来检查该方法。有关示例,请参阅 BitBlt 代码不起作用。有关
Bitblt
的一些信息,请参阅 http://www .codeproject.com/KB/GDI-plus/flicker_free.aspx。You could use the
Bitblt
P/Invoke, which copies image data directly. It does require some initialisation to convert the image data to something the display device understands, but this copy operation is lightning fast. If you would like to know what exactly is happening inDrawImage
btw, use a tool like ILSpy or Reflector.NET to inspect the method.See BitBlt code not working for an example. For some information about
Bitblt
see http://www.codeproject.com/KB/GDI-plus/flicker_free.aspx.