e.Graphics.DrawImage()反向 [英] e.Graphics.DrawImage() in reverse

查看:150
本文介绍了e.Graphics.DrawImage()反向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们



我这样做了:



Hey guys

I have done this:

Dim ShouldPaintImage2 as boolean=true
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
       e.Graphics.DrawImage(My.Resources.image1, 20, 20)
if ShouldPaintImage2=true then
[remove old graphic]
 e.Graphics.DrawImage(My.Resources.image2, 20, 20)
End Sub





是否可以删除 仅图像 的图形,以便将图像更改为图像2?



谢谢



Is it possible to remove only the graphic of image1 so i can change the image to image2?

Thanks

推荐答案

当然可以。您需要了解您正在使用的 OnPaint 是否在Windows WM_PAINT 消息上调用,您的UI收到每个失效:

http://msdn.microsoft.com/en -us / library / 598t492a.aspx [ ^ ]。



请查看我过去的答案:

mdi子窗体之间的绘制线 [ ^ ],

在面板上捕获图纸 [ ^ ],

什么样的俏皮方法是Paint? (DataGridViewImageCell.Paint(...)) [ ^ ],

如何加速我的vb.net应用程序? [ ^ ]。



也就是说,你只需要这样:绘制不是固定的图像,而是绘制可变图像/位图参考。引用 Image ,例如,您的表单类的实例字段;让我们说,它的名字是 MyImage 。那么 DrawImage 的行应该更改为 e.Graphics.DrawImage(MyImage ...)



现在,切换图像的过程看起来像



Yes of course. You need to understand that OnPaint, which you are correctly using, is called on the Windows WM_PAINT messages, which your UI receives on each invalidation:
http://msdn.microsoft.com/en-us/library/598t492a.aspx[^].

Please see my past answers:
Drawing Lines between mdi child forms[^],
capture the drawing on a panel[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
How to speed up my vb.net application?[^].

That said, all you need is this: Draw not a fixed image, but a variable image/bitmap reference. Make a reference to Image an instance field of, say, your form class; let''s say, its name is MyImage. Then your line with DrawImage should be changes to e.Graphics.DrawImage(MyImage ...).

Now, the procedure of "switching the image" will look like

MyImage = ' different reference, ether image1 or image2...
self.Invalidate(); ' this will eventually cause re-painting
' here, "self" is your control, of the class where you override OnPaint;
' it could be your form or whatever control it is...





你明白了吗?



-SA


我想你以错误的方式解决这个问题,如果情况确实如此,那么首先不把它绘制起来会更有意义吗?即:

I think you''re going about this the wrong way, wouldn''t it make more sense to just not draw it in the first place if that''s the case? i.e.:
Dim ShouldPaintImage2 as boolean=true
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
    If ShouldPaintImage2=true Then
        e.Graphics.DrawImage(My.Resources.image2, 20, 20)
    Else
        e.Graphics.DrawImage(My.Resources.image1, 20, 20)
    End If
End Sub



(对不起,如果这不是完美的话正确的语法,我的VB.Net非常生疏)



否则,据我所知,你不能删除一个特定的对象,如果你的真实代码更复杂,清除图形,然后使用image2而不是image1重绘整个图形。


(Sorry if this isn''t perfectly correct syntax, my VB.Net is very rusty)

Otherwise, to my knowledge you can''t erase a specific object, if your real code is more complicated, clear the drawing, then redraw the whole thing, using image2 instead of image1.


这篇关于e.Graphics.DrawImage()反向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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