本文整理汇总了C#中Graphics.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# Graphics.Clear方法的具体用法?C# Graphics.Clear怎么用?C# Graphics.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graphics
的用法示例。
在下文中一共展示了Graphics.Clear方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public static void Run()
{
// ExStart:DrawingBezier
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_DrawingAndFormattingImages();
// Creates an instance of FileStream
using (FileStream stream = new FileStream(dataDir + "DrawingArc_out.bmp", FileMode.Create))
{
// Create an instance of BmpOptions and set its various properties
BmpOptions saveOptions = new BmpOptions();
saveOptions.BitsPerPixel = 32;
// Set the Source for BmpOptions and create an instance of Image
saveOptions.Source = new StreamSource(stream);
using (Image image = Image.Create(saveOptions, 100, 100))
{
// Create and initialize an instance of Graphics class and clear Graphics surface
Graphics graphic = new Graphics(image);
graphic.Clear(Color.Yellow);
// Draw an arc shape by specifying the Pen object having red black color and coordinates, height, width, start & end angles
int width = 100;
int height = 200;
int startAngle = 45;
int sweepAngle = 270;
// Draw arc to screen and save all changes.
graphic.DrawArc(new Pen(Color.Black), 0, 0, width, height, startAngle, sweepAngle);
image.Save();
}
stream.Close();
}
}
示例2: Run
public static void Run()
{
// ExStart:DrawingEllipse
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_DrawingAndFormattingImages();
// Creates an instance of FileStream
using (FileStream stream = new FileStream(dataDir + "DrawingEllipse_out.bmp", FileMode.Create))
{
// Create an instance of BmpOptions and set its various properties
BmpOptions saveOptions = new BmpOptions();
saveOptions.BitsPerPixel = 32;
saveOptions.Source = new StreamSource(stream);
// Create an instance of Image
using (Image image = Image.Create(saveOptions, 100, 100))
{
// Create and initialize an instance of Graphics class and Clear Graphics surface
Graphics graphic = new Graphics(image);
graphic.Clear(Color.Yellow);
// Draw a dotted ellipse shape by specifying the Pen object having red color and a surrounding Rectangle
graphic.DrawEllipse(new Pen(Color.Red), new Rectangle(30, 10, 40, 80));
// Draw a continuous ellipse shape by specifying the Pen object having solid brush with blue color and a surrounding Rectangle
graphic.DrawEllipse(new Pen(new SolidBrush(Color.Blue)), new Rectangle(10, 30, 80, 40));
image.Save();
}
stream.Close();
}
// ExEnd:DrawingEllipse
}
示例3: Run
public static void Run()
{
// ExStart:DrawingLines
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_DrawingAndFormattingImages() + "SolidLines_out.bmp";
// Creates an instance of FileStream
using (FileStream stream = new FileStream(dataDir, FileMode.Create))
{
// Create an instance of BmpOptions and set its various properties
BmpOptions saveOptions = new BmpOptions();
saveOptions.BitsPerPixel = 32;
saveOptions.Source = new StreamSource(stream);
// Create an instance of Image
using (Image image = Image.Create(saveOptions, 100, 100))
{
// Create and initialize an instance of Graphics class and Clear Graphics surface
Graphics graphic = new Graphics(image);
graphic.Clear(Color.Yellow);
// Draw two dotted diagonal lines by specifying the Pen object having blue color and co-ordinate Points
graphic.DrawLine(new Pen(Color.Blue), 9, 9, 90, 90);
graphic.DrawLine(new Pen(Color.Blue), 9, 90, 90, 9);
// Draw a four continuous line by specifying the Pen object having Solid Brush with red color and two point structures
graphic.DrawLine(new Pen(new SolidBrush(Color.Red)), new Point(9, 9), new Point(9, 90));
graphic.DrawLine(new Pen(new SolidBrush(Color.Aqua)), new Point(9, 90), new Point(90, 90));
graphic.DrawLine(new Pen(new SolidBrush(Color.Black)), new Point(90, 90), new Point(90, 9));
graphic.DrawLine(new Pen(new SolidBrush(Color.White)), new Point(90, 9), new Point(9, 9));
image.Save();
}
}
// ExEnd:DrawingLines
}
示例4: Run
public static void Run()
{
// ExStart:DrawingRectangle
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_DrawingAndFormattingImages() + "SampleRectangle_out.bmp";
// Creates an instance of FileStream
using (FileStream stream = new FileStream(dataDir, FileMode.Create))
{
// Create an instance of BmpOptions and set its various properties
BmpOptions saveOptions = new BmpOptions();
saveOptions.BitsPerPixel = 32;
// Set the Source for BmpOptions and Create an instance of Image
saveOptions.Source = new StreamSource(stream);
using (Image image = Image.Create(saveOptions, 100, 100))
{
// Create and initialize an instance of Graphics class, Clear Graphics surface, Draw a rectangle shapes and save all changes.
Graphics graphic = new Graphics(image);
graphic.Clear(Color.Yellow);
graphic.DrawRectangle(new Pen(Color.Red), new Rectangle(30, 10, 40, 80));
graphic.DrawRectangle(new Pen(new SolidBrush(Color.Blue)), new Rectangle(10, 30, 80, 40));
image.Save();
}
}
// ExEnd:DrawingRectangle
}
示例5: Run
public static void Run()
{
// ExStart:DrawingUsingGraphics
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_DrawingAndFormattingImages() + "SampleImage_out.bmp";
// Create an instance of BmpOptions and set its various properties
BmpOptions imageOptions = new BmpOptions();
imageOptions.BitsPerPixel = 24;
// Create an instance of FileCreateSource and assign it to Source property
imageOptions.Source = new FileCreateSource(dataDir, false);
using (var image = Image.Create(imageOptions, 500, 500))
{
var graphics = new Graphics(image);
// Clear the image surface with white color and Create and initialize a Pen object with blue color
graphics.Clear(Color.White);
var pen = new Pen(Color.Blue);
// Draw Ellipse by defining the bounding rectangle of width 150 and height 100 also Draw a polygon using the LinearGradientBrush
graphics.DrawEllipse(pen, new Rectangle(10, 10, 150, 100));
using (var linearGradientBrush = new LinearGradientBrush(image.Bounds, Color.Red, Color.White, 45f))
{
graphics.FillPolygon(linearGradientBrush, new[] { new Point(200, 200), new Point(400, 200), new Point(250, 350) });
}
image.Save();
}
// ExEnd:DrawingUsingGraphics
}
示例6: PaintDocumentGradientBackground
public static void PaintDocumentGradientBackground(Graphics graphics, Rectangle rectangle)
{
LinearGradientBrush BackgroundBrush = new LinearGradientBrush(rectangle, DefaultGradientUpper, DefaultGradientLower, LinearGradientMode.Vertical);
graphics.Clear(DefaultGradientUpper);
graphics.FillRectangle(BackgroundBrush, rectangle);
BackgroundBrush.Dispose();
}
示例7: arm
//Graphics g_,Graphics g1_)
public arm()
{
//g = g_;
//g1 = g1_;
armBmp = new Bitmap(800, 400);
drawBmp = new Bitmap(400,400);
g = Graphics.FromImage(armBmp);
g.Clear(Color.White);
g1 = Graphics.FromImage(drawBmp);
g1.Clear(Color.White);
}
示例8: OnPaint
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
G = e.Graphics;
G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
G.Clear(BackColor);
G.SmoothingMode = SmoothingMode.AntiAlias;
GP1 = ThemeModule.CreateRound(0, 0, Width - 1, Height - 1, 7);
GP2 = ThemeModule.CreateRound(1, 1, Width - 3, Height - 3, 7);
if (IsMouseDown)
{
PB1 = new PathGradientBrush(GP1);
PB1.CenterColor = Color.FromArgb(60, 60, 60);
PB1.SurroundColors = new Color[] { Color.FromArgb(55, 55, 55) };
PB1.FocusScales = new PointF(0.8f, 0.5f);
G.FillPath(PB1, GP1);
}
else
{
GB1 = new LinearGradientBrush(ClientRectangle, Color.FromArgb(60, 60, 60), Color.FromArgb(55, 55, 55), 90f);
G.FillPath(GB1, GP1);
}
G.DrawPath(P1, GP1);
G.DrawPath(P2, GP2);
SZ1 = G.MeasureString(Text, Font);
PT1 = new PointF(5, Height / 2 - SZ1.Height / 2);
if (IsMouseDown)
{
PT1.X += 1f;
PT1.Y += 1f;
}
G.DrawString(Text, Font, Brushes.Black, PT1.X + 1, PT1.Y + 1);
G.DrawString(Text, Font, Brushes.White, PT1);
}
示例9: Run
public static void Run()
{
// ExStart:DrawingBezier
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_DrawingAndFormattingImages();
// Creates an instance of FileStream
using (FileStream stream = new FileStream(dataDir + "DrawingBezier_out.bmp", FileMode.Create))
{
// Create an instance of BmpOptions and set its various properties
BmpOptions saveOptions = new BmpOptions();
saveOptions.BitsPerPixel = 32;
// Set the Source for BmpOptions and Create an instance of Image
saveOptions.Source = new StreamSource(stream);
using (Image image = Image.Create(saveOptions, 100, 100))
{
// Create and initialize an instance of Graphics class and clear Graphics surface
Graphics graphic = new Graphics(image);
graphic.Clear(Color.Yellow);
// Initializes the instance of PEN class with black color and width
Pen BlackPen = new Pen(Color.Black, 3);
float startX = 10;
float startY = 25;
float controlX1 = 20;
float controlY1 = 5;
float controlX2 = 55;
float controlY2 = 10;
float endX = 90;
float endY = 25;
// Draw a Bezier shape by specifying the Pen object having black color and co-ordinate Points and save all changes.
graphic.DrawBezier(BlackPen, startX, startY, controlX1, controlY1, controlX2, controlY2, endX, endY);
image.Save();
}
}
// ExEnd:DrawingBezier
}
示例10: Run
public static void Run()
{
// ExStart:DrawingUsingGraphicsPath
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_DrawingAndFormattingImages();
// Create an instance of BmpOptions and set its various properties
BmpOptions ImageOptions = new BmpOptions();
ImageOptions.BitsPerPixel = 24;
// Create an instance of FileCreateSource and assign it to Source property
ImageOptions.Source = new FileCreateSource(dataDir + "sample_1.bmp", false);
// Create an instance of Image and initialize an instance of Graphics
using (Image image = Image.Create(ImageOptions, 500, 500))
{
Graphics graphics = new Graphics(image);
graphics.Clear(Color.White);
// Create an instance of GraphicsPath and Instance of Figure, add EllipseShape, RectangleShape and TextShape to the figure
GraphicsPath graphicspath = new GraphicsPath();
Figure figure = new Figure();
figure.AddShape(new EllipseShape(new RectangleF(0, 0, 499, 499)));
figure.AddShape(new RectangleShape(new RectangleF(0, 0, 499, 499)));
figure.AddShape(new TextShape("Aspose.Imaging", new RectangleF(170, 225, 170, 100), new Font("Arial", 20), StringFormat.GenericTypographic));
graphicspath.AddFigures(new[] { figure });
graphics.DrawPath(new Pen(Color.Blue), graphicspath);
// Create an instance of HatchBrush and set its properties also Fill path by supplying the brush and GraphicsPath objects
HatchBrush hatchbrush = new HatchBrush();
hatchbrush.BackgroundColor = Color.Brown;
hatchbrush.ForegroundColor = Color.Blue;
hatchbrush.HatchStyle = HatchStyle.Vertical;
graphics.FillPath(hatchbrush, graphicspath);
image.Save();
Console.WriteLine("Processing completed successfully.");
}
// ExEnd:DrawingUsingGraphicsPath
}
示例11: Run
public static void Run()
{
// ExStart:CombineImages
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_DrawingAndFormattingImages();
// Create an instance of JpegOptions and set its various properties
JpegOptions imageOptions = new JpegOptions();
// Create an instance of FileCreateSource and assign it to Source property
imageOptions.Source = new FileCreateSource(dataDir + "Two_images_result_out.bmp", false);
// Create an instance of Image and define canvas size
using (var image = Image.Create(imageOptions, 600, 600))
{
// Create and initialize an instance of Graphics, Clear the image surface with white color and Draw Image
var graphics = new Graphics(image);
graphics.Clear(Color.White);
graphics.DrawImage(Image.Load(dataDir + "sample_1.bmp"), 0, 0, 600, 300);
graphics.DrawImage(Image.Load(dataDir + "File1.bmp"), 0, 300, 600, 300);
image.Save();
}
// ExEnd:CombineImages
}
示例12: OnPaint
protected override void OnPaint(PaintEventArgs e)
{
G = e.Graphics;
G.Clear(BackColor);
G.SmoothingMode = SmoothingMode.AntiAlias;
GP1 = ThemeModule.CreateRound(0, 0, Width - 1, Height - 1, 7);
GP2 = ThemeModule.CreateRound(1, 1, Width - 3, Height - 3, 7);
PB1 = new PathGradientBrush(GP1);
PB1.CenterColor = Color.FromArgb(50, 50, 50);
PB1.SurroundColors = new Color[] { Color.FromArgb(45, 45, 45) };
PB1.FocusScales = new PointF(0.9f, 0.5f);
G.FillPath(PB1, GP1);
G.DrawPath(P1, GP1);
G.DrawPath(P2, GP2);
G.SmoothingMode = SmoothingMode.None;
for (int I = 0; I <= Table.Length - 1; I++)
{
int C = Math.Max(Table[I], (byte)75);
int X = ((I % RowSize) * ItemSize) + WA.X;
int Y = ((I / RowSize) * ItemSize) + WA.Y;
B2 = new SolidBrush(Color.FromArgb(C, C, C));
G.FillRectangle(B1, X + 1, Y + 1, DrawSize, DrawSize);
G.FillRectangle(B2, X, Y, DrawSize, DrawSize);
B2.Dispose();
}
}
示例13: UpdateGraphics
private void UpdateGraphics(Graphics g)
{
g.Clear(Color.FromArgb (255, 255, 255, 255));
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
Pen p = new Pen (new SolidBrush (Color.Black));
SolidBrush r = new SolidBrush (Color.Red);
renderer.Polygon demoObject = CreateTestPolygon ();
demoObject.Draw2D (p, g);
LineTest (testLine1, g, 0);
LineTest (testLine2, g, Math.PI/100);
try
{
Console.Write(testLine1.FindLineLineIntersection (testLine2));
testLine1.DrawPoint(g, testLine1.FindLineLineIntersection (testLine2), new SolidBrush(Color.Purple));
}
catch (ArgumentException e) {
Console.WriteLine ("Invalid arguments");
}
foreach (Node element in nodeList)
{
element.Draw(g);
}
}