本文介绍了如何保留渲染图形信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要保存我绘制的图形的信息.它可以显示窗口何时再次显示.大多数是不规则图形.请帮助我!谢谢!

我想将绘制的图像保存到数据库中,因此下次打开窗口时,可以看到绘制的图像.

I want save the information of the graphics that i paint. And it can show when the windows show again. Most are Irregular graphics. Please Help me !Thanks!

I want to save the drawn into the DataBase ,so Next time i opening the window that i can see what i drawn and drawn where!

推荐答案

Graphics g = e.Graphics;

如果您不使用Paint事件,应该这样做,否则您的图形将不会持久化-如果将其最小化然后还原,则矩形将消失.

为什么不创建List< Rectangle>其中包含您要绘制的矩形?

If you aren''t using the Paint event, you should be, or your drawings will not be persistent in the form - if you minimise it and then restore, your rectangle will disappear.

Why not create a List<Rectangle> which contains the rectangles you want to draw?

List<rectangle> myListOfRectangles = new List<rectangle>();</rectangle></rectangle>


然后在您的Paint事件中:


Then in your Paint event:

private void myPanelToDrawOn_Paint(object sender, PaintEventArgs e)
    {
    Graphics g = e.Graphics;
    using (Brush b = new SolidBrush(Color.Blue))
        {
        using (Pen p = new Pen(b))
            {
            foreach (Rectangle r in myListOfRectangles)
                {
                g.DrawRectangle(p, r);
                }
            }
        }
    }

如果在类级别创建列表,则可以在需要时使用

If you create the list at class level, you can use

myListOfRectangles.Add(new Rectangle(x, y, w, h));

,并在其后调用Invalidate方法重画批次.
然后,您要做的就是在停止和启动应用程序时将矩形"保存并还原到文件中.

when you need to, and follow it with a call to the Invalidate method to redraw the lot.
Then all you have to do is save and restore the Rectangles to a file when you stop and start your app.


这篇关于如何保留渲染图形信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 20:39
查看更多