当前位置: 首页>>代码示例>>C#>>正文


C# Graphics.Dispose方法代码示例

本文整理汇总了C#中System.Drawing.Graphics.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Graphics.Dispose方法的具体用法?C# Graphics.Dispose怎么用?C# Graphics.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Drawing.Graphics的用法示例。


在下文中一共展示了Graphics.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Draw

        public override void Draw(System.Drawing.RectangleF dirtyRect)
        {
            var g = new Graphics();

            // NSView does not have a background color so we just use Clear to white here
            g.Clear(Color.White);

            //RectangleF ClientRectangle = this.Bounds;
            RectangleF ClientRectangle = dirtyRect;

            // Calculate the location and size of the drawing area
            // within which we want to draw the graphics:
            Rectangle rect = new Rectangle((int)ClientRectangle.X, (int)ClientRectangle.Y,
                                           (int)ClientRectangle.Width, (int)ClientRectangle.Height);
            drawingRectangle = new Rectangle(rect.Location, rect.Size);
            drawingRectangle.Inflate(-offset, -offset);
            //Draw ClientRectangle and drawingRectangle using Pen:
            g.DrawRectangle(Pens.Red, rect);
            g.DrawRectangle(Pens.Black, drawingRectangle);
            // Draw a line from point (3,2) to Point (6, 7)
            // using the Pen with a width of 3 pixels:
            Pen aPen = new Pen(Color.Green, 3);
            g.DrawLine(aPen, Point2D(new PointF(3, 2)),
                       Point2D(new PointF(6, 7)));

            g.PageUnit = GraphicsUnit.Inch;
            ClientRectangle = new RectangleF(0.5f,0.5f, 1.5f, 1.5f);
            aPen.Width = 1 / g.DpiX;
            g.DrawRectangle(aPen, ClientRectangle);

            aPen.Dispose();

            g.Dispose();
        }
开发者ID:stnk3000,项目名称:sysdrawing-coregraphics,代码行数:34,代码来源:DrawingView.cs

示例2: Draw

        private void Draw(Graphics gr)
        {
            Bitmap bitmap = new Bitmap(Width, Height);
            Graphics g = Graphics.FromImage(bitmap);

            g.FillRectangle(BlackBrush, 10, 10, 100, 250);

            Color c;
            Brush b;
            switch (s.Color)
            {
                case TrafficLightColor.Red:
                    c = Color.Red;
                    b = new SolidBrush(c);
                    g.FillEllipse(b, 25, 25, 70, 70);
                    break;
                case TrafficLightColor.Yellow:
                    c = Color.Yellow;
                    b = new SolidBrush(c);
                    g.FillEllipse(b, 25, 95, 70, 70);
                    break;
                case TrafficLightColor.Green:
                    c = Color.Green;
                    b = new SolidBrush(c);
                    g.FillEllipse(b, 25, 165, 70, 70);
                    break;
            }

            gr.DrawImage(bitmap, 0, 0, Width, Height);
            gr.Dispose();
            bitmap.Dispose();
            g.Dispose();
        }
开发者ID:JackalTabaqui,项目名称:TrafficLights,代码行数:33,代码来源:Form1.cs

示例3: T_Tick

 private void T_Tick(object sender, EventArgs e)
 {
     this.SuspendLayout();
     state = obj.GetState;
     int istate = 1;
     try {  istate = Convert.ToInt32(state);
         state += "%";
     }
     catch (Exception ex) {}
     rect.Size = new Size(this.Width - 1, this.Height - 1);
     bmp = new Bitmap(this.Width, this.Height);
     g = Graphics.FromImage(bmp);
     g.DrawRectangle(new Pen(Color.Black), rect);
     g.FillRectangle(Brushes.Blue, new Rectangle(1, 1, rect.Width - 1, rect.Height - 1));
     g.FillRectangle(Brushes.White, new Rectangle(1, 1, rect.Width - 1, (int)(rect.Height-rect.Height*0.01* istate)));
     using (Font _normalFont = new Font("Century Gothic", 48, FontStyle.Regular, GraphicsUnit.Point))
     {
         StringFormat stringFormat = new StringFormat();
         stringFormat.Alignment = StringAlignment.Center;
         stringFormat.LineAlignment = StringAlignment.Center;
         g.DrawString(state, _normalFont, Brushes.Black,rect,stringFormat);
     }
     g.Dispose();
     this.BackgroundImage = bmp;
     this.ResumeLayout();
 }
开发者ID:rwalicki,项目名称:inteligentny_dom,代码行数:26,代码来源:stateForm.cs

示例4: t_Tick

        private void t_Tick(object sender, EventArgs e)
        {
            //graphics
            g = Graphics.FromImage(bmp);

            //clear graphics
            g.Clear(Color.LightSkyBlue);

            //draw progressbar
            g.FillRectangle(Brushes.CornflowerBlue, new Rectangle(0, 0, (int)(pbComplete * pbUnit), pbHEIGHT));

            //draw % complete
            g.DrawString(pbComplete + "%", new Font("Arial", pbHEIGHT / 2), Brushes.Black, new PointF(pbWIDTH / 2 - pbHEIGHT, pbHEIGHT / 10));

            //load bitmap in picturebox picboxPB
            picboxPB.Image = bmp;

            //update pbComplete
            //Note!
            //To keep things simple I am adding +1 to pbComplete every 50ms
            //You can change this as per your requirement :)
            pbComplete++;
            if (pbComplete > 100)
            {
                //dispose
                g.Dispose();
                t.Stop();
            }

        }
开发者ID:wangrui523,项目名称:CSharp-Project,代码行数:30,代码来源:Form1.cs

示例5: DrawFormBackgroud

        public void DrawFormBackgroud(Graphics g, Rectangle r)
        {
            drawing = new Bitmap(this.Width, this.Height, g);
            gg = Graphics.FromImage(drawing);

            Rectangle shadowRect = new Rectangle(r.X, r.Y, r.Width, 10);
            Rectangle gradRect = new Rectangle(r.X, r.Y + 9, r.Width, 42);
            //LinearGradientBrush shadow = new LinearGradientBrush(shadowRect, Color.FromArgb(30, 41, 61), Color.FromArgb(47, 64, 94), LinearGradientMode.Vertical);
            LinearGradientBrush shadow = new LinearGradientBrush(shadowRect, Color.FromArgb(30, 61, 41), Color.FromArgb(47, colorR, 64), LinearGradientMode.Vertical);
            //LinearGradientBrush grad = new LinearGradientBrush(gradRect, Color.FromArgb(47, 64, 94), Color.FromArgb(49, 66, 95), LinearGradientMode.Vertical);
            LinearGradientBrush grad = new LinearGradientBrush(gradRect, Color.Green, Color.DarkGreen, LinearGradientMode.Vertical);
            ColorBlend blend = new ColorBlend();

            // Set multi-color gradient
            blend.Positions = new[] { 0.0f, 0.35f, 0.5f, 0.65f, 1.0f };
            //blend.Colors = new[] { Color.FromArgb(47, 64, 94), Color.FromArgb(64, 88, 126), Color.FromArgb(66, 90, 129), Color.FromArgb(64, 88, 126), Color.FromArgb(49, 66, 95) };
            blend.Colors = new[] { Color.FromArgb(47,colorR, 64), Color.FromArgb(64, colorR+32, 88), Color.FromArgb(66, colorR+35, 90), Color.FromArgb(64, colorR+32, 88), Color.FromArgb(49, colorR+1, 66) };
            grad.InterpolationColors = blend;
            Font myf=new System.Drawing.Font(this.Font.FontFamily,16);
            // Draw basic gradient and shadow
            //gg.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            gg.FillRectangle(grad, gradRect);
            gg.FillRectangle(shadow, shadowRect);
            gg.DrawString("Добавить один ПК", myf, Brushes.GhostWhite, new PointF(55, 15));
            gg.DrawImage(Properties.Resources.singleAdd1.ToBitmap(), 10, 10,32,32);

            g.DrawImageUnscaled(drawing, 0, 0);
            gg.Dispose();

            // Draw checkers
            //g.FillRectangle(checkers, r);
        }
开发者ID:fenriv,项目名称:NetOpen,代码行数:32,代码来源:SinglePCAdd.cs

示例6: ProcessEMF

 public void ProcessEMF(byte[] emf)
 {
     try
     {
         _ms = new MemoryStream(emf);
         _mf = new Metafile(_ms);
         _bm = new Bitmap(1, 1);
         g = Graphics.FromImage(_bm);
         //XScale = Width / _mf.Width;
         //YScale = Height/ _mf.Height;
         m_delegate = new Graphics.EnumerateMetafileProc(MetafileCallback);
         g.EnumerateMetafile(_mf, new Point(0, 0), m_delegate);
     }
     finally
     {
         if (g != null)
             g.Dispose();
         if (_bm != null)
             _bm.Dispose();
         if (_ms != null)
         {
             _ms.Close();
             _ms.Dispose();
         }
     }
 }
开发者ID:NelsonSantos,项目名称:fyiReporting-Android,代码行数:26,代码来源:EMF.cs

示例7: DrawFormBackgroud

        public void DrawFormBackgroud(Graphics g, Rectangle r)
        {
            drawing = new Bitmap(this.Width, AnimSize, g);
            gg = Graphics.FromImage(drawing);

            Rectangle shadowRect = new Rectangle(r.X, r.Y, r.Width, 10);
            Rectangle gradRect = new Rectangle(r.X, r.Y + 9, r.Width, AnimSize-9);
            LinearGradientBrush shadow = new LinearGradientBrush(shadowRect, Color.FromArgb(30, 61, 61), Color.FromArgb(47, colorR, colorR), LinearGradientMode.Vertical);
            //LinearGradientBrush shadow = new LinearGradientBrush(shadowRect, Color.FromArgb(30, 61, 41), Color.FromArgb(47, colorR, 64), LinearGradientMode.Vertical);
            LinearGradientBrush grad = new LinearGradientBrush(gradRect, Color.FromArgb(47, 64, 94), Color.FromArgb(49, 66, 95), LinearGradientMode.Vertical);
            //LinearGradientBrush grad = new LinearGradientBrush(gradRect, Color.Green, Color.DarkGreen, LinearGradientMode.Vertical);
            ColorBlend blend = new ColorBlend();

            // Set multi-color gradient
            blend.Positions = new[] { 0.0f, 0.35f, 0.5f, 0.65f, 0.95f,1f };
            blend.Colors = new[] { Color.FromArgb(47, colorR, colorR), Color.FromArgb(64, colorR + 22, colorR + 32), Color.FromArgb(66, colorR + 20, colorR + 35), Color.FromArgb(64, colorR + 20, colorR + 32), Color.FromArgb(49, colorR, colorR + 1), SystemColors.Control };
            //blend.Colors = new[] { Color.FromArgb(47, colorR, 64), Color.FromArgb(64, colorR + 32, 88), Color.FromArgb(66, colorR + 35, 90), Color.FromArgb(64, colorR + 32, 88), Color.FromArgb(49, colorR + 1, 66),SystemColors.Control };
            grad.InterpolationColors = blend;
            Font myf = new System.Drawing.Font(this.Font.FontFamily, 16);
            // Draw basic gradient and shadow
            //gg.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            gg.FillRectangle(grad, gradRect);
            gg.FillRectangle(shadow, shadowRect);
            gg.TextRenderingHint = TextRenderingHint.AntiAlias;
            gg.DrawString("Поиск по ресурсам сети", myf, Brushes.GhostWhite, new PointF(55, 15));
            gg.DrawImage(Properties.Resources.search1.ToBitmap(), 10, 10,32,32);

            g.DrawImageUnscaled(drawing, 0, 0);
            gg.Dispose();

            // Draw checkers
            //g.FillRectangle(checkers, r);
        }
开发者ID:fenriv,项目名称:NetOpen,代码行数:33,代码来源:ShareSearch.cs

示例8: DrawRect

        public override void DrawRect(System.Drawing.RectangleF dirtyRect)
        {
            //			var gc = NSGraphicsContext.FromGraphicsPort(
            //				NSGraphicsContext.CurrentContext.GraphicsPort.Handle,true);

            //			var gc = NSGraphicsContext.CurrentContext;
            //
            //			var g = new Graphics(gc.GraphicsPort);
            var g = new Graphics();

            // NSView does not have a background color so we just use Clear to white here
            g.Clear(Color.White);

            //RectangleF ClientRectangle = this.Bounds;
            RectangleF ClientRectangle = dirtyRect;

            // Following codes draw a line from (0, 0) to (1, 1) in unit of inch:
            /*g.PageUnit = GraphicsUnit.Inch;
            Pen blackPen = new Pen(Color.Black, 1/g.DpiX);
            g.DrawLine(blackPen, 0, 0, 1, 1);*/

            // Following code shifts the origin to the center of
            // client area, and then draw a line from (0,0) to (1, 1) inch:
            g.PageUnit = GraphicsUnit.Inch;
            g.TranslateTransform((ClientRectangle.Width / g.DpiX) / 2,
                                 (ClientRectangle.Height / g.DpiY) / 2);
            Pen greenPen = new Pen(Color.Green, 1 /  g.DpiX);
            g.DrawLine(greenPen, 0, 0, 1, 1);

            g.Dispose ();
        }
开发者ID:stnk3000,项目名称:sysdrawing-coregraphics,代码行数:31,代码来源:DrawingView.cs

示例9: Enemy

 static Enemy()
 {
     _mdl = OBJModelParser.GetInstance().Parse("res/mdl/enemy");
     _garbage = new Bitmap(1, 1);
     _garbageg = Graphics.FromImage(_garbage);
     List<Pair<string, Rect2D>> quotes = new List<Pair<string, Rect2D>>();
     using (StreamReader s = new StreamReader("res/screams.txt")) {
         while (!s.EndOfStream) {
             string q = s.ReadLine();
             while (q.EndsWith(@"\")) {
                 q = q.Substring(0, q.Length - 1);
                 q += "\n";
                 q += s.ReadLine();
             }
             SizeF size = _garbageg.MeasureString(q, SystemFonts.DefaultFont);
             Bitmap img = new Bitmap((int)size.Width + 6, (int)size.Height + 6);
             Graphics g = Graphics.FromImage(img);
             g.FillRectangle(Brushes.White, 0, 0, img.Width, img.Height);
             g.DrawString(q, SystemFonts.DefaultFont, Brushes.Black, 3, 3);
             g.Dispose();
             Pair<string, Rect2D> ins = new Pair<string, Rect2D>();
             ins.First = q;
             const int SCALE = 30;
             const int SCALE2 = 2 * SCALE;
             ins.Second = new Rect2D(img,
                     -(size.Width / SCALE2), -(size.Height / SCALE2),
                     (size.Width / SCALE), (size.Height / SCALE));
             quotes.Add(ins);
         }
     }
     _garbageg.Dispose();
     _garbageg = null; //Prevent accidental use.
     _quotes = quotes.ToArray();
     _r = new Random();
 }
开发者ID:bobtwinkles,项目名称:Defence,代码行数:35,代码来源:Enemy.cs

示例10: button1_Click

 // Clear Button
 private void button1_Click(object sender, EventArgs e)
 {
     bmp = new Bitmap(400, 400);
     g = Graphics.FromImage(bmp);
     g.Clear(Color.White);
     pictureBox1.Image = bmp;
     g.Dispose();
 }
开发者ID:mitkonikov,项目名称:Nikov-Drawing-Library,代码行数:9,代码来源:Form1.cs

示例11: Wallpaper

        public Wallpaper()
        {
            s = Settings.Instance;
            allScreen = MultiScreenInfo.Instance;
            CanAddAnotherBitmap = true;

            try
            {
                desktop = new Bitmap(allScreen.VirtualDesktop.Width, allScreen.VirtualDesktop.Height);
                gDesktop = Graphics.FromImage(desktop);
                gDesktop.SetHighQuality();
                needFullRedraw = true;

                try
                {
                    if (allScreen.IsChanged == false)
                    {
                        var currentPath = GetCurrentPath();
                        var expectedPath = SafeFilename.Convert(s.SaveFolder, "Current Wallpaper.bmp", true);

                        if (currentPath == expectedPath)
                        {
                            using (var currentDesktop = new Bitmap(currentPath))
                            {
                                //not needed?
                                if (currentDesktop.Size == allScreen.VirtualDesktop.Size)
                                {
                                    gDesktop.DrawImageUnscaled(currentDesktop, 0, 0);
                                    needFullRedraw = false;
                                }
                            }
                        }
                    }
                }
                catch
                {
                }
            }
            catch
            {
                if (gDesktop != null)
                {
                    gDesktop.Dispose();
                    gDesktop = null;
                }

                if (desktop != null)
                {
                    desktop.Dispose();
                    desktop = null;
                }
            }

            if (desktop == null)
            {
                throw new ArgumentException();
            }
        }
开发者ID:iamxail,项目名称:DailyWallpainter,代码行数:58,代码来源:Wallpaper.cs

示例12: T_Tick

 private void T_Tick(object sender, EventArgs e)
 {
     g = Graphics.FromImage(bmp);
     g.Clear(Color.Transparent);
     g.FillRectangle(new SolidBrush(Color.FromArgb(68, 10, 79)),new Rectangle(new Point(0,0),new Size(Width,y)));
     if(y<GetResolution.GetHeight) y += i;
     box.Image = bmp;
     g.Dispose();
 }
开发者ID:rwalicki,项目名称:inteligentny_dom,代码行数:9,代码来源:TestForm.cs

示例13: DisplayValue

 private void DisplayValue(int value, PictureBox picBox)
 {
     point = GetPoint(value);
     valueImage = GetBitmap(value);
     valueToImageWriter = Graphics.FromImage(valueImage);
     valueToImageWriter.DrawString(value.ToString(), font, brush, point);
     picBox.Image = valueImage;
     valueToImageWriter.Dispose();
 }
开发者ID:Joop7,项目名称:yamb-game,代码行数:9,代码来源:frmBestHighscore.cs

示例14: Draw

 public void Draw(Graphics panelGraphics, Dictionary<Guid, DrawableNode> allNodes)
 {
     System.Drawing.Pen myPen;
     myPen = new System.Drawing.Pen(System.Drawing.Color.DodgerBlue, 3f);
     myPen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
     panelGraphics.DrawLine(myPen, allNodes[TailNodeGuid].Location.X + 25, allNodes[TailNodeGuid].Location.Y + 25, allNodes[HeadNodeGuid].Location.X + 25, allNodes[HeadNodeGuid].Location.Y + 25);
     myPen.Dispose();
     panelGraphics.Dispose();
 }
开发者ID:Egris,项目名称:Hydra,代码行数:9,代码来源:DrawAbleConnector.cs

示例15: MainForm

        public MainForm()
        {
            InitializeComponent();

            snapshotDrawArea = new Bitmap(panelDrawArea.ClientRectangle.Width, panelDrawArea.ClientRectangle.Height);   //Creating layer for drawing

            g = Graphics.FromImage(snapshotDrawArea);                                        //fill layer with white color for normal saving process
            g.FillRectangle(Brushes.White, 0, 0, panelDrawArea.ClientRectangle.Width, panelDrawArea.ClientRectangle.Height);
            g.Dispose();
        }
开发者ID:SimTolik,项目名称:HomePainter,代码行数:10,代码来源:MainForm.cs


注:本文中的System.Drawing.Graphics.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。