在现有位图上添加元素 [英] add elements on existing bitmap

查看:64
本文介绍了在现有位图上添加元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有

i有一个图片框然后在其中绘制一个矩形并使用用户表格永久使用

然后我为其他用户的这个矩形添加一个圆圈形式,并使其永久也

问题是,当我尝试修改圆圈的位置时,它绘制一个新的并且不要删除旧的

如果我绘制一个新的矩形,所有圆圈消失

(我想修改圆圈位置并删除旧圆圈,我想修改矩形尺寸而不删除现有圆圈)



我的代码如下:



dear all
i have a picture box then draw a rectangle in it and make it permanent using a user form
then i add a circle to this rectangle by other user form and make it permanent also
the problem is when i try to modify the location of the circle it draw a new one and do not remove old one
and if i draw a new rectangle the all circles disappears
(i want to modify the circles location and remove old one, i want to modify the rectangle dimensions without remove the existing circles)

my code as follow:

Module Module2
    Public canvas As Bitmap
    Public mygraphics As Graphics
    Public Sub draw_rec(ByVal points(,) As Double)

        Dim canavas_x As Integer = frm_main.pb_preview.Width
        Dim canavas_y As Integer = frm_main.pb_preview.Height / 2
        canvas = New Bitmap(canavas_x, canavas_y)
        mygraphics = Graphics.FromImage(canvas)
        Dim myPen As System.Drawing.Pen
        myPen = New System.Drawing.Pen(System.Drawing.Color.Black)
        myPen.Width = 0.0
        mygraphics.Clear(Color.White)
        mygraphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
        For k = 0 To UBound(points, 1) - 1
            mygraphics.DrawLine(myPen, Convert.ToSingle(points(k, 0)), Convert.ToSingle(points(k, 1)), Convert.ToSingle(points(k + 1, 0)), Convert.ToSingle(points(k + 1, 1)))
        Next
        frm_main.pb_preview.Image = canvas 'make the image permenant
    End Sub
    Public Sub draw_cir()
        Dim myPen As System.Drawing.Pen
        myPen = New System.Drawing.Pen(System.Drawing.Color.Black)
        myPen.Width = 0.0
        Dim mygraphics1 = Graphics.FromImage(canvas)
        mygraphics1.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias

        For k = 0 To UBound(cicles, 1) - 1
            x = Convert.ToSingle(cicles(k, 1) - 0.5 * cicles(k, 3))
            y = Convert.ToSingle(cicles(k, 2) - 0.5 * cicles(k, 3))
            mygraphics1.DrawEllipse(myPen, x, y, Convert.ToSingle(cicles(k, 3)), Convert.ToSingle(cicles(k, 3)))
        Next
        frm_main.pb_preview.Image = canvas 'make the image permenant


    End Sub
End Module

推荐答案

使用 PictureBox <使事情变得复杂很多/ code>。它根本没有帮助,只会增加一些麻烦,消耗额外的资源和开发时间,不给予任何回报。我会解释做什么。请查看我过去的答案:

在其中附加图片图片框 [ ^ ],

画一个矩形C# [ ^ ],

如何从旧图纸中清除面板 [ ^ ]。



这些答案应该解释你如何通过更改图像进行图形渲染,例如交互式和/ o动画:

捕获图纸面板 [ ^ ],

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

mdi子表单之间的绘制线 [ ^ ],

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

用动画在运行时更改图片的任何方式 [ ^ ],

如何根据e.graphics的内容制作文件 [ ^ ]。



我希望你有主要想法:1你渲染图形将其模型保存在内存中,2)你通过改变模型和调用 Invalidate 方法来改变图形,3)你通过使用双缓冲来避免闪烁。



-SA
You complicate thing a lot by using PictureBox. It does not help you at all, only adds some hassles and consume extra resource and your development time, giving nothing in return. I'll explain what do to. Please see my past answers:
Append a picture within picturebox[^],
draw a rectangle in C#[^],
How do I clear a panel from old drawing[^].

And these answers should explain you how to do graphics rendering with changing images, such as interactive and/or animated:
capture the drawing on a panel[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
Drawing Lines between mdi child forms[^],
How to speed up my vb.net application?[^],
any way to change a picture at run time with animation[^],
how to make a file from the content of e.graphics[^].

I hope you got the main ideas: 1) you render graphics keeping its model in memory, 2) you change graphics by changing the model and calling of of the Invalidate methods, 3) you avoid flicker by using double buffering.

—SA


谢谢谢尔盖,我会(尝试+学习)这个技术,直到当我遇到问题时你
thanks Sergey, i will (try+learn) this Technic and till you when i had a problem


这篇关于在现有位图上添加元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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