如何告诉OnPaint()不要重绘背景图像? [英] How can I tell OnPaint() not to repaint the background image?

查看:247
本文介绍了如何告诉OnPaint()不要重绘背景图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我正在使用UserControl在其上加载.tif文件.之后,我将使用GDI API在加载到UserControl中的图片上方绘制线条和矩形.到目前为止,一切正常.但问题是,每当我在UserControl上绘制新的Rectangle/Line时,UserControl就会失效并重新粉刷.矩形/直线应重新绘制,就是这种情况.但是图像无需再次重绘.一方面,图像一旦加载就不会改变.其次,图像的大小远大于100MB,因此每次我调用Invalidate()时都要重新绘制图像,这会使我的应用程序变慢.

我知道有一种方法可以使OnPaint()仅绘制UserControl的特定部分,但事实是,TIF图像和其他形状绘制在同一区域上.即首先绘制图像,然后在其顶部绘制形状.就像有层次感.我想做的是强制Invalidate()仅重绘上层的形状,而不一直向下绘制图像.据我所知,GDI没有像OpenGL中那样的"Z"坐标.这意味着,我将无法告诉我的应用程序不要重新绘制图像.
因此,如果您知道解决此问题的方法,我将不胜感激.

在此先感谢

Hi guys. I am using a UserControl to load a .tif file on it. After that I am using the GDI API to draw lines and rectangles on top of the Image loaded into the UserControl. So far that is working fine. But the thing is, when ever I draw a new Rectangle/Line on on the UserControl, the UserControl is Invalidated and is repainted. The Rectangles/Lines should be redrawn and that is the case. But the Image need not be redrawn again. For one thing, the Image doesn''t change once it is loaded. Second, the size of the image is well above 100MB so repainting it every time I call Invalidate() is making my application slow.

I know there is a way to make OnPaint() to paint only the specific part of the UserControl but the thing is, the TIF image and the other shapes are drawn on the same area. i.e the image is drawn first and on top of it the shapes. It is like there is a layering. What I am trying to do is to force Invalidate() to repaint only the shapes on the upper layer without going all the way to down to the image. As far as I know GDI doesn''t have a ''Z'' coordinate like that in OpenGL. Which means, I won''t be able to tell my application not to repaint the image.
So, if you know a workaround to this problem, I would greatly appreciate it.

Thanks in advance

推荐答案

也请参见Control类的SetStyles方法来设置 Uwe
Please see also the SetStyles method of a Control class to set the ControlStyles[^].

By using these styles, you can control various things like background painting (See the Opaque enum member).

Cheers
Uwe


您可以覆盖OnPaintBackground()函数来控制执行什么操作/何时执行绘画. 此处 [
You could override the OnPaintBackground() function to control what/when it does its painting. Here[^] is a link to the MSDN, there is a note to inheritors about not calling the base.


好吧,每个Control上已经有两层:由OnPaint绘制的一层和由OnPaintBackground绘制的一层.因此,您可以简单地将Image加载为ControlBackgroundImage,并在OnPaint中绘制所有其他内容.
Well, there are already 2 layers on every Control: the one painted by OnPaint and the one painted by OnPaintBackground. So, you can simply load your Image as the Control''s BackgroundImage and draw all the other stuff in OnPaint.


这篇关于如何告诉OnPaint()不要重绘背景图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆