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


C# Graphics.Dispose方法代码示例

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


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

示例1: FromImageImage1

private void FromImageImage1(PaintEventArgs e)
{
    // Create image.
    Image imageFile = Image.FromFile("SampImag.jpg");
             
    // Create graphics object for alteration.
    Graphics newGraphics = Graphics.FromImage(imageFile);
             
    // Alter image.
    newGraphics.FillRectangle(new SolidBrush(Color.Black), 100, 50, 100, 100);
             
    // Draw image to screen.
    e.Graphics.DrawImage(imageFile, new PointF(0.0F, 0.0F));
             
    // Release graphics object.
    newGraphics.Dispose();
}
开发者ID:.NET开发者,项目名称:System.Drawing,代码行数:17,代码来源:Graphics.Dispose

示例2: Graphics.Dispose()

//引入命名空间
using System;
using System.Drawing;
using System.Windows.Forms;
   
class BlockOut: Form
{
     bool      bBlocking, bValidBox;
     Point     ptBeg, ptEnd;
     Rectangle rectBox;
   
     public static void Main()
     {
          Application.Run(new BlockOut());
     }
     protected override void OnMouseDown(MouseEventArgs mea)
     {
          if (mea.Button == MouseButtons.Left)
          {
               ptBeg = ptEnd = new Point(mea.X, mea.Y);
   
               Graphics grfx = CreateGraphics();
               grfx.DrawRectangle(new Pen(ForeColor), Rect(ptBeg, ptEnd));
               grfx.Dispose();
   
               bBlocking = true;
          }
     }
     protected override void OnMouseMove(MouseEventArgs mea)
     {
          if (bBlocking)
          {
               Graphics grfx = CreateGraphics();
               grfx.DrawRectangle(new Pen(BackColor), Rect(ptBeg, ptEnd));
               ptEnd = new Point(mea.X, mea.Y);
               grfx.DrawRectangle(new Pen(ForeColor), Rect(ptBeg, ptEnd));
               grfx.Dispose();
               Invalidate();
          }
     }
     protected override void OnMouseUp(MouseEventArgs mea)
     {
          if (bBlocking && mea.Button == MouseButtons.Left)
          {
               Graphics grfx = CreateGraphics();
               rectBox = Rect(ptBeg, new Point(mea.X, mea.Y));
               grfx.DrawRectangle(new Pen(ForeColor), rectBox);
               grfx.Dispose();
   
               bBlocking = false;
               bValidBox = true;
               Invalidate();
          }
     }
     protected override void OnPaint(PaintEventArgs pea)
     {
          Graphics grfx = pea.Graphics;
   
          if (bValidBox)
               grfx.FillRectangle(new SolidBrush(ForeColor), rectBox);
   
          if (bBlocking)
               grfx.DrawRectangle(new Pen(ForeColor), Rect(ptBeg, ptEnd));
     }
     Rectangle Rect(Point ptBeg, Point ptEnd)
     {
          return new Rectangle(Math.Min(ptBeg.X, ptEnd.X),
                               Math.Min(ptBeg.Y, ptEnd.Y),
                               Math.Abs(ptEnd.X - ptBeg.X),
                               Math.Abs(ptEnd.Y - ptBeg.Y));
     }
}
开发者ID:C#程序员,项目名称:System.Drawing,代码行数:72,代码来源:Graphics.Dispose


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