本文整理汇总了C#中System.Drawing.Graphics.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# Graphics.Clear方法的具体用法?C# Graphics.Clear怎么用?C# Graphics.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Graphics
的用法示例。
在下文中一共展示了Graphics.Clear方法的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();
}
示例2: RectangleTransparent
public RectangleTransparent()
{
clearPen = new Pen(Color.FromArgb(1, 0, 0, 0));
borderDotPen = new Pen(Color.Black, 1);
borderDotPen2 = new Pen(Color.White, 1);
borderDotPen2.DashPattern = new float[] { 5, 5 };
penTimer = Stopwatch.StartNew();
ScreenRectangle = CaptureHelpers.GetScreenBounds();
surface = new Bitmap(ScreenRectangle.Width, ScreenRectangle.Height);
gSurface = Graphics.FromImage(surface);
gSurface.InterpolationMode = InterpolationMode.NearestNeighbor;
gSurface.SmoothingMode = SmoothingMode.HighSpeed;
gSurface.CompositingMode = CompositingMode.SourceCopy;
gSurface.CompositingQuality = CompositingQuality.HighSpeed;
gSurface.Clear(Color.FromArgb(1, 0, 0, 0));
StartPosition = FormStartPosition.Manual;
Bounds = ScreenRectangle;
Text = "ShareX - " + Resources.RectangleTransparent_RectangleTransparent_Rectangle_capture_transparent;
Shown += RectangleLight_Shown;
KeyUp += RectangleLight_KeyUp;
MouseDown += RectangleLight_MouseDown;
MouseUp += RectangleLight_MouseUp;
using (MemoryStream cursorStream = new MemoryStream(Resources.Crosshair))
{
Cursor = new Cursor(cursorStream);
}
timer = new Timer { Interval = 10 };
timer.Tick += timer_Tick;
timer.Start();
}
示例3: EnsureTemporaryBitmap
private void EnsureTemporaryBitmap( int width, int height )
{
if( bmp != null )
{
if( bmp.Width >= width && bmp.Height >= height )
{
g.Clear( Color.Black );
return;
}
width = Math.Max( width, bmp.Width );
height = Math.Max( height, bmp.Height );
}
Helpers.DisposeAndClear( ref g );
Helpers.DisposeAndClear( ref bmp );
bmp = new Bitmap( width, height, PixelFormat.Format32bppRgb );
g = Graphics.FromImage( bmp );
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
g.Clear( Color.Black );
}
示例4: DrawPieChart
public void DrawPieChart()
{
g = Graphics.FromImage(bitmapd);
g.Clear(System.Drawing.Color.AliceBlue);
int a = db.getCountFromDB("select count(*) from music");
DataTable dt = db.getQueryFromDB("select distinct Genre from music");
int index = 0;
int[] myPiePercent = new int[dt.Rows.Count];
string [] values=new string[dt.Rows.Count];
foreach (DataRow r in dt.Rows)
{
string s = r[0].ToString();
int b = db.getCountFromDB(string.Format("select count(*) from music where Genre='{0}'", s));
myPiePercent[index] = (int)Math.Ceiling(((double)b * 100 / a));
values[index] = s;
index++;
}
System.Drawing.Color[] myPieColors = { c1, c2, c3, c4 };
g.Clear(System.Drawing.Color.AliceBlue);
System.Drawing.Size myPieSize ;
System.Drawing.Point myPieLocation ;
if (x < y)
{
myPieSize= new System.Drawing.Size(x - 50, x - 50);
myPieLocation = new System.Drawing.Point(x / 2, x / 2);
}
else
{
myPieSize = new System.Drawing.Size(y - 50, y - 50);
myPieLocation = new System.Drawing.Point(y / 2, y / 2);
}
int PiePercentTotal = 0;
for (int PiePercents = 0; PiePercents < myPiePercent.Length; PiePercents++)
{
using (SolidBrush brush = new SolidBrush(myPieColors[PiePercents]))
{
g.FillPie(brush, new System.Drawing.Rectangle(new System.Drawing.Point(10, 10), myPieSize), Convert.ToSingle(PiePercentTotal * 360 / 100), Convert.ToSingle(myPiePercent[PiePercents] * 360 / 100));
}
PiePercentTotal += myPiePercent[PiePercents];
}
double xx = 0, yy = 0;
for (int k = 0; k < index; k ++)
{
yy = Math.Sin(100*k*Math.PI/180) * 90;
xx = Math.Cos(k*100 * Math.PI / 180) * 90;
//g.DrawRectangle(new System.Drawing.Pen(System.Drawing.Color.Black), myPieLocation.X+(int)xx,myPieLocation.Y+ (int)yy, 5, 5);
g.DrawString(values[k], new System.Drawing.Font("Sans", 10), System.Drawing.Brushes.Black, myPieLocation.X-30+(float)xx, myPieLocation.Y+(float)yy);
}
}
示例5: Draw
public void Draw(Graphics g)
{
g.Clear(Color.Gray);
PointF cellSize = new PointF((float)Size.X / (ChessGameField.FIELD_SIZE), (float)Size.Y / (ChessGameField.FIELD_SIZE));
for (int i = 0; i <= ChessGameField.FIELD_SIZE; ++i)
{
g.DrawLine(Pens.Black, Pos.X + i * cellSize.X, Pos.Y, Pos.X + i * cellSize.X, Pos.Y + Size.Y);
}
for (int i = 0; i <= ChessGameField.FIELD_SIZE; ++i)
{
g.DrawLine(Pens.Black, Pos.X, Pos.Y + i * cellSize.Y, Pos.X + Size.X, Pos.Y + i * cellSize.Y);
}
Field.ForEachCell((pos, cell) => { if (cell.figure != null) cell.figure.Draw(g, GetColor(cell.figure.GetOwner()), GetCellPos(pos, cellSize), cellSize); return true; });
if (State == ActionState.Selected)
{
PointF pos = GetCellPos(SelectedPoint, cellSize);
Pen pen = new Pen(Brushes.Green, 2);
int border = 4;
g.DrawRectangle(pen, new Rectangle((int)pos.X + border + 1, (int)pos.Y + border + 1, (int)cellSize.X - border*2, (int)cellSize.Y - border*2));
}
}
示例6: DrawPDF417
public void DrawPDF417(ref Graphics g)
{
g.Clear(this.backcolor);
SolidBrush brush = new SolidBrush(this.forecolor);
int x = this.leftmargin;
int y = this.topmargin;
SizeF ef = g.MeasureString(this.bottomcomment, this.txtFont, 0x7fffffff, StringFormat.GenericTypographic);
for (int i = 0; i < this.encodebinarystr.Length; i++)
{
char ch = this.encodebinarystr[i];
switch (ch)
{
case '0':
x += this.modulewidth;
break;
case '1':
g.FillRectangle(brush, x, y, this.modulewidth, this.moduleheight);
x += this.modulewidth;
break;
default:
if (ch == 'Z')
{
y += this.moduleheight;
x = this.leftmargin;
}
break;
}
}
g.DrawString(this.topcomment, this.txtFont, brush, (float) this.topcommentleftmargin, (float) this.topcommenttopmargin);
//g.DrawString(" ", this.txtFont, brush, (float) 0f, (float) (this.symbolheight - ef.Height));
brush.Dispose();
}
示例7: wypelniony
private void wypelniony()
{
bmp = new Bitmap((int)pbWIDTH, (int)pbHEIGHT);
Point p1 = new Point((int)(pbWIDTH / 6), (int)(pbHEIGHT / 2));
Point p2 = new Point((int)(pbWIDTH * 5 / 6), (int)(pbHEIGHT / 2));
Point p1_25 = new Point(pbWIDTH / 3, pbHEIGHT / 4 * 3);
Point p2_25 = new Point((int)(pbWIDTH / 3 * 2), (int)(pbHEIGHT / 4 * 3));
Point p1_75 = new Point((int)(pbWIDTH / 3), (int)(pbHEIGHT / 4));
Point p2_75 = new Point((int)(pbWIDTH / 3 * 2), (int)(pbHEIGHT / 4));
Pen pen1 = new Pen(Brushes.Black, width_pen1);
Pen pen2 = new Pen(Brushes.Black, width_pen2);
g = Graphics.FromImage(bmp);
g.Clear(Color.CornflowerBlue);
g.FillRectangle(Brushes.White, new Rectangle(0, 0, pbWIDTH, pbHEIGHT - (int)(pbComplete * pbUnit)));
g.DrawRectangle(pen1, 0, 0, pbWIDTH, pbHEIGHT);
g.DrawLine(pen2, p1, p2);
g.DrawLine(pen2, p1_25, p2_25);
g.DrawLine(pen2, p1_75, p2_75);
//g.DrawString(pbComplete + "%", new Font("Arial", pbHEIGHT / 5),Brushes.Black,new PointF(pbWIDTH/12,pbHEIGHT/4));
this.Image = bmp;
//return bmp;
}
示例8: CDrawWinForm
public CDrawWinForm()
{
this.Icon = new System.Drawing.Icon(Path.Combine(System.Environment.CurrentDirectory, CSettings.sIcon));
_Textures = new List<STexture>();
_Bitmaps = new List<Bitmap>();
_Keys = new CKeys();
_Mouse = new CMouse();
this.ClientSize = new Size(1280, 720);
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.Opaque, true);
// Create the backbuffer
_backbuffer = new Bitmap(CSettings.iRenderW, CSettings.iRenderH);
_g = Graphics.FromImage(_backbuffer);
_g.Clear(Color.DarkBlue);
this.Paint += new PaintEventHandler(this.OnPaintEvent);
this.Closing += new CancelEventHandler(this.OnClosingEvent);
this.KeyDown += new KeyEventHandler(this.OnKeyDownEvent);
this.KeyPress += new KeyPressEventHandler(this.OnKeyPressEvent);
this.KeyUp += new KeyEventHandler(this.OnKeyUpEvent);
this.Resize += new EventHandler(this.OnResizeEvent);
this.MouseMove += new MouseEventHandler(this.OnMouseMove);
this.MouseDown += new MouseEventHandler(this.OnMouseDown);
this.MouseUp += new MouseEventHandler(this.OnMouseUp);
FlipBuffer();
Cursor.Show();
}
示例9: Render
//Render a Drawing
public static void Render(DnaDrawing drawing,Graphics g,int scale)
{
g.Clear(Tools.avgColour);
foreach (DnaPolygon polygon in drawing.Polygons)
Render(polygon, g, scale);
}
示例10: CreateContext
public IDisposable CreateContext()
{
_gfx = Graphics.FromImage(_bitmap);
_gfx.Init();
_gfx.Clear(System.Drawing.Color.Transparent);
return _gfx;
}
示例11: Render
//Render a Drawing
public static void Render(DnaDrawing drawing,Graphics g,int scale)
{
g.Clear(Color.Black);
foreach (DnaPolygon polygon in drawing.Polygons)
Render(polygon, g, scale);
}
示例12: PaintPalette
// ���»���
public void PaintPalette(Graphics gp)
{
gp.Clear(this._bgColor);
this._food.Paint(gp);
foreach (Block b in this._blocks)
b.Paint(gp);
}
示例13: Bitmap
void Former.new21file()
{
pixels = new PixelButton[64, 32];
map = new Bitmap(64,32);
gra = Graphics.FromImage(map);
gra.Clear(Color.Transparent);
}
示例14: ResizeImg
/// <summary>
/// 压缩图片,返回map
/// </summary>
/// <param name="width">宽度</param>
/// <param name="height">高度</param>
/// <returns></returns>
public Bitmap ResizeImg(int width, int height)
{
if (_oldImg == null)
return null;
int ow = _oldImg.Width, oh = _oldImg.Height; //原始大小
if (height == -2)
{
var rale = (double)width / Math.Max(ow, oh); //压缩比例
width = (int)Math.Ceiling(ow * rale);
height = (int)Math.Ceiling(oh * rale);
}
else
{
width = (width != -1 ? width : ow);
height = (height != -1 ? height : oh);
}
var bm = new Bitmap(width, height, PixelFormat.Format32bppRgb);
_newGraphics = Graphics.FromImage(bm);
//呈现质量
_newGraphics.CompositingQuality = CompositingQuality.HighQuality;
//像素偏移方式
_newGraphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
//平滑处理
_newGraphics.SmoothingMode = SmoothingMode.HighQuality;
//插补模式,双三次插值法
_newGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
_newGraphics.Clear(Color.Transparent);
_newGraphics.DrawImage(_oldImg, new Rectangle(0, 0, width, height), new Rectangle(0, 0, ow, oh),
GraphicsUnit.Pixel);
//return "处理成功";
return bm;
}
示例15: FormMain
public FormMain()
{
InitializeComponent();
BGpath = currentDir + @"DATA\IMG\background.jpg";
CHpath = currentDir + @"DATA\IMG\actor.png";
btnSTART.Enabled = false;
btnStep.Enabled = false;
checkBG.Checked = checkCH.Checked = checkTXT.Checked = true;
btnBackColor.BackColor = Color.White;
btnForeColor.ForeColor = Color.White;
btnBackColor.ForeColor = Color.Black;
btnForeColor.BackColor = Color.Black;
Label lab = new Label();
lab.BackColor = Color.Transparent;
ThumbPicCH.Controls.Add(lab);
btnStep.Text = "��ʼ��������";
GThumb = panel1.CreateGraphics();
GThumb.Clear(Color.White);
LoadFile();
}