如何保留渲染图形信息 [英] How to preserve rendering graphics information

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

问题描述

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

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

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!

推荐答案

好了,您可以开始通过查看告诉Paint方法必须绘制的方式.
既然您必须告诉它一些东西,那就是您需要保存的东西.

如何保存?不能说-在至少不了解您从中汲取什么以及可以存储到哪种媒体(数据库,文本文件,配置文件,您自己的数据文件格式等)方面的情况下,我们真的无法会更有帮助.告诉我们您正在做什么和需要做什么的更多信息,我们将为您提供更好的信息!


例如:Graphics g = new Graphics();画笔b = new SolidBrush(Color.Blue); Pen p = new Pen(b); g.DrawRectangle(p,New Rectangle(10,20,30, 40)); ---------------------------------------------- ------编写代码,绘制矩形.要保存矩形的属性,下次运行应用程序时,再次显示矩形."

首先,不要那样做!为什么不呢?
1)如果创建Graphics对象,则负责处理它-它们是一种稀缺资源,并且用完它们的速度将比Garbage Collector能够处理它们快得多!这将在您的程序中导致无法预料的错误.这也适用于画笔和笔-如果永远不变,请将其移出绘画方法!

2)如果要处理Paint事件,则会将相应的Graphics对象作为PaintEventArgs参数的一部分.
Well, you could start by looking at the way you tell the Paint method what it has to draw.
Since you have to tell it something, that something is what you need to save.

How to save it? Can''t say - without knowing at least something about what you are drawing from, and what media you have available to store into (database, text file, config file, your own datafile format, etc.) we really can''t be a lot more helpful. Tell us more about what you are doing and need to do, and we will give you better information!


"Such as: Graphics g=new Graphics (); Brush b=new SolidBrush(Color.Blue); Pen p=new Pen(b); g.DrawRectangle(p,New Rectangle(10,20,30,40)); ---------------------------------------------------- Up the Code I write ,I Paint a Rectangle.And I want to save the Rectangle''s Properties,When next time I run the Application then show the Rectangle again."

Firstly, don''t do that! Why not?
1) If you create a Graphics object you are responsible for disposing of it - they are a scarce resource, and you will run out of them a lot faster than the Garbage Collector get get round to Disposing them! This will cause unpredictable errors in you program. This also applies to Brushes and Pens - so move them outside your painting method if they never change!

2) If you are handling the Paint event then you are handed the appropriate Graphics object as part of the PaintEventArgs parameter.
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.


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

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