1/39
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Graphics
A class in the System.Drawing namespace that represents a drawing surface and provides methods for drawing shapes, text, and images. Domain: C# → .NET → System.Drawing → 2D Drawing & Rendering
Graphics g = Graphics.FromImage(bitmap);
Creates a Graphics object that can be used to draw onto an existing Image or Bitmap.
using Graphics g = Graphics.FromImage(bitmap);
Creates a Graphics object for an image and automatically disposes it when execution leaves its scope.
g.DrawLine(pen, x1, y1, x2, y2);
Draws a line between two specified coordinate points using a Pen.
g.DrawLines(pen, points);
Draws a sequence of connected line segments through an array of points using a Pen.
g.DrawRectangle(pen, x, y, width, height);
Draws the outline of a rectangle using the specified Pen, position, width, and height.
g.FillRectangle(brush, x, y, width, height);
Fills the interior of a rectangle using the specified Brush.
g.DrawEllipse(pen, x, y, width, height);
Draws the outline of an ellipse inside the specified bounding rectangle. Equal width and height produce a circle.
g.FillEllipse(brush, x, y, width, height);
Fills the interior of an ellipse using the specified Brush.
g.DrawPolygon(pen, points);
Draws the outline of a polygon defined by an array of points.
g.FillPolygon(brush, points);
Fills the interior of a polygon defined by an array of points.
g.DrawArc(pen, rectangle, startAngle, sweepAngle);
Draws a portion of an ellipse defined by a bounding rectangle, starting angle, and sweep angle.
g.DrawPie(pen, rectangle, startAngle, sweepAngle);
Draws the outline of a pie-shaped section defined by an elliptical arc and lines connecting the arc to its center.
g.FillPie(brush, rectangle, startAngle, sweepAngle);
Fills the interior of a pie-shaped section using the specified Brush.
g.DrawCurve(pen, points);
Draws a smooth curve through an array of specified points.
g.DrawBezier(pen, p1, p2, p3, p4);
Draws a cubic Bézier curve using two endpoint coordinates and two control points.
g.DrawString("Hello", font, brush, x, y);
Draws text at the specified position using a Font to control typography and a Brush to control how the text is filled.
SizeF size = g.MeasureString("Hello", font);
Measures the approximate dimensions required to draw the specified text using a particular Font.
g.DrawImage(image, x, y);
Draws an image at the specified coordinates.
g.DrawImage(image, x, y, width, height);
Draws an image at the specified coordinates and scales it to the specified width and height.
g.DrawImageUnscaled(image, x, y);
Draws an image at its original pixel dimensions without scaling it.
g.Clear(Color.White);
Clears the entire drawing surface and fills it with the specified Color.
g.TranslateTransform(x, y);
Translates the Graphics coordinate system by the specified horizontal and vertical amounts.
g.RotateTransform(angle);
Rotates the Graphics coordinate system by the specified angle in degrees.
g.ScaleTransform(scaleX, scaleY);
Scales the Graphics coordinate system by the specified horizontal and vertical scale factors.
g.ResetTransform();
Resets the Graphics transformation matrix to the identity transformation.
g.SmoothingMode = SmoothingMode.AntiAlias;
Enables anti-aliased rendering for supported lines, curves, and shape edges to make them appear smoother.
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
Sets a high-quality bicubic interpolation mode used when images are scaled or transformed.
g.TextRenderingHint = TextRenderingHint.AntiAlias;
Sets the text-rendering behavior to use anti-aliasing for smoother text edges.
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
Sets high-quality pixel-offset behavior used during rendering.
g.SetClip(rectangle);
Restricts subsequent drawing operations to the specified clipping region.
g.ResetClip();
Resets the clipping region so drawing is no longer restricted by the previously specified custom clip.
GraphicsState state = g.Save();
Saves the current Graphics state, including transformations and clipping information, so it can later be restored.
g.Restore(state);
Restores a Graphics object to a state that was previously saved with Save().
g.Dispose();
Releases resources associated with the Graphics object.
Drawing Surface
The destination onto which a Graphics object renders shapes, text, and images, such as a Bitmap or another supported graphics surface.
Pen
An object used by Graphics drawing methods to define how lines and shape outlines are rendered, including properties such as color and width.
Brush
An object used to define how the interiors of shapes and text are filled when rendered by Graphics.
Graphics Transformation
A modification of the Graphics coordinate system that changes how subsequently drawn objects are positioned, rotated, or scaled.
Anti-Aliasing
A rendering technique that reduces jagged-looking edges by blending pixels around the boundaries of lines, curves, shapes, or text.