本文整理汇总了C#中Graphics类的典型用法代码示例。如果您正苦于以下问题:C# Graphics类的具体用法?C# Graphics怎么用?C# Graphics使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Graphics类属于命名空间,在下文中一共展示了Graphics类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
public override void Draw(Graphics gr)
{
if (Ready)
{
gr.DrawRectangle(Pens.Green, Left, Top, Right, Bottom);
}
}
示例2: Run
public static void Run()
{
// ExStart:AddWatermarkToImage
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages();
// Create an instance of Image and load an existing image
using (Image image = Image.Load(dataDir + "WaterMark.bmp"))
{
// Create and initialize an instance of Graphics class
Graphics graphics = new Graphics(image);
// Creates an instance of Font
Font font = new Font("Times New Roman", 16, FontStyle.Bold);
// Create an instance of SolidBrush and set its various properties
SolidBrush brush = new SolidBrush();
brush.Color = Color.Black;
brush.Opacity = 100;
// Draw a String using the SolidBrush object and Font, at specific Point and Save the image with changes.
graphics.DrawString("Aspose.Imaging for .Net", font, brush, new PointF(image.Width / 2, image.Height / 2));
image.Save(dataDir + "AddWatermarkToImage_out.bmp");
// ExStart:AddWatermarkToImage
// Display Status.
Console.WriteLine("Watermark added successfully.");
}
}
示例3: Draw
public override void Draw(Graphics e)
{
Point[] PointArray = new Point[PointList.Count];
PointArray = PointList.ToArray();
for (int i = 0; i < PointList.Count; i++)
e.DrawLines(new Pen(Color.Black), PointArray);
}
示例4: 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();
}
}
示例5: Start
// Use this for initialization
void Start()
{
curve = new Curve();
graphics = new Graphics();
graphics.verticesDrawer = verticesDrawer;
}
示例6: DrawStreched
void DrawStreched(Graphics g, Rectangle dest)
{
g.Draw(texture, new Rectangle(dest.X, dest.Y, paddingLeft, paddingTop),
new Rectangle(0, 0, paddingLeft, paddingTop), border);
g.Draw(texture, new Rectangle(dest.X + paddingLeft, dest.Y, dest.Width - paddingLeft - paddingRight, paddingTop),
new Rectangle(paddingLeft, 0, texture.Width - paddingLeft - paddingRight, paddingTop), border);
g.Draw(texture, new Rectangle(dest.X + dest.Width - paddingRight, dest.Y, paddingLeft, paddingTop),
new Rectangle(texture.Width - paddingRight, 0, paddingLeft, paddingTop), border);
g.Draw(texture, new Rectangle(dest.X, dest.Y + paddingTop, paddingLeft, dest.Height - paddingTop - paddingBottom),
new Rectangle(0, paddingTop, paddingLeft, texture.Height - paddingTop - paddingBottom), border);
g.Draw(texture, new Rectangle(dest.X + paddingLeft, dest.Y + paddingTop, dest.Width - paddingLeft - paddingRight, dest.Height - paddingTop - paddingBottom),
new Rectangle(paddingLeft, paddingTop, texture.Width - paddingLeft - paddingRight, texture.Height - paddingLeft - paddingRight), color);
g.Draw(texture, new Rectangle(dest.X + dest.Width - paddingRight, dest.Y + paddingTop, paddingRight, dest.Height - paddingTop - paddingBottom),
new Rectangle(texture.Width - paddingRight, paddingTop, paddingRight, texture.Height - paddingTop - paddingBottom), border);
g.Draw(texture, new Rectangle(dest.X, dest.Y + dest.Height - paddingBottom, paddingLeft, paddingBottom),
new Rectangle(0, texture.Height - paddingBottom, paddingLeft, paddingBottom), border);
g.Draw(texture, new Rectangle(dest.X + paddingLeft, dest.Y + dest.Height - paddingBottom, dest.Width - paddingLeft - paddingRight, paddingBottom),
new Rectangle(paddingLeft, texture.Height - paddingBottom, texture.Width - paddingLeft - paddingRight, paddingBottom), border);
g.Draw(texture, new Rectangle(dest.X + dest.Width - paddingRight, dest.Y + dest.Height - paddingBottom, paddingLeft, paddingBottom),
new Rectangle(texture.Width - paddingRight, texture.Height - paddingBottom, paddingLeft, paddingBottom), border);
}
示例7: Draw
public void Draw(Graphics graphics, Size buffersize)
{
//store transform, (like opengl's glPushMatrix())
Matrix mat1 = graphics.Transform;
//transform into position
graphics.TranslateTransform(m_position.X, m_position.Y);
graphics.RotateTransform(m_angle/(float)Math.PI * 180.0f);
try
{
//draw body
graphics.DrawRectangle(new Pen(m_color), rect);
//draw line in the "forward direction"
graphics.DrawLine(new Pen(Color.Yellow), 1, 0, 1, 5);
}
catch(OverflowException exc)
{
//physics overflow :(
}
//restore transform
graphics.Transform = mat1;
}
示例8: CylinderPrimitive
public CylinderPrimitive(Graphics graphicsDevice)
{
Debug.Assert (_tessellation >= 3);
// Create a ring of triangles around the outside of the cylinder.
for (int i = 0; i <= _tessellation; i++) {
Vector3 normal = GetCircleVector (i, _tessellation);
Vector3 topPos = normal * _radius + Vector3.Up * _height;
Vector3 botPos = normal * _radius + Vector3.Down * _height;
AddVertex (topPos, normal);
AddVertex (botPos, normal);
}
for (int i = 0; i < _tessellation; i++) {
AddIndex (i * 2);
AddIndex (i * 2 + 1);
AddIndex ((i * 2 + 2));
AddIndex (i * 2 + 1);
AddIndex (i * 2 + 3);
AddIndex (i * 2 + 2);
}
// Create flat triangle fan caps to seal the top and bottom.
CreateCap (_tessellation, _height, _radius, Vector3.Up);
CreateCap (_tessellation, _height, _radius, Vector3.Down);
InitializePrimitive (graphicsDevice);
}
示例9: GetBaseLineHeight
/// <summary>
/// Gets the baseline Height of the rectangle
/// </summary>
/// <param name="g"></param>
/// <returns></returns>
public float GetBaseLineHeight(CssBox b, Graphics g)
{
Font f = b.ActualFont;
FontFamily ff = f.FontFamily;
FontStyle s = f.Style;
return f.GetHeight(g) * ff.GetCellAscent(s) / ff.GetLineSpacing(s);
}
示例10: ApplyTextWatermark
protected override void ApplyTextWatermark(ImageProcessingActionExecuteArgs args, Graphics g)
{
// Draw a filled rectangle
int rectangleWidth = 14;
using (Brush brush = new SolidBrush(Color.FromArgb(220, Color.Red)))
{
g.FillRectangle(brush, new Rectangle(args.Image.Size.Width - rectangleWidth, 0, rectangleWidth, args.Image.Size.Height));
}
using (System.Drawing.Drawing2D.Matrix transform = g.Transform)
{
using (StringFormat stringFormat = new StringFormat())
{
// Vertical text (bottom -> top)
stringFormat.FormatFlags = StringFormatFlags.DirectionVertical;
transform.RotateAt(180F, new PointF(args.Image.Size.Width / 2, args.Image.Size.Height / 2));
g.Transform = transform;
// Align: top left, +2px displacement
// (because of the matrix transformation we have to use inverted values)
base.ContentAlignment = ContentAlignment.MiddleLeft;
base.ContentDisplacement = new Point(-2, -2);
base.ForeColor = Color.White;
base.Font.Size = 10;
// Draw the string by invoking the base Apply method
base.StringFormat = stringFormat;
base.ApplyTextWatermark(args, g);
base.StringFormat = null;
}
}
}
示例11: Render
public virtual void Render(Graphics g)
{
for (int i = 0; i < _Particles.Count; i++)
{
_Particles[i].Render(g);
}
}
示例12: 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
}
示例13: Draw
public void Draw(Graphics g, int x, int y, int frame)
{
north[frame].Draw(g,x,y-(int)((PckImage.Width*PckImage.Scale)/2));
south[frame].Draw(g,x,y);
east[frame].Draw(g,x+(int)((PckImage.Width*PckImage.Scale)/2),y-(int)((PckImage.Width*PckImage.Scale)/4));
west[frame].Draw(g,x-(int)((PckImage.Width*PckImage.Scale)/2),y-(int)((PckImage.Width*PckImage.Scale)/4));
}
示例14: RenderModel
void RenderModel(Graphics.Content.Model10 model, SlimDX.Matrix entityWorld, Effect effect)
{
throw new NotImplementedException();
//if (model == null || !model.Visible || model.Mesh == null) return;
Matrix world = model.World * entityWorld;
world.M41 = (float)((int)world.M41);
world.M42 = (float)((int)world.M42);
world *= Matrix.Scaling(2f / (float)view.Viewport.Width, 2f / (float)view.Viewport.Height, 1) * Matrix.Translation(-1, -1, 0) * Matrix.Scaling(1, -1, 1);
world.M43 = 0.5f;
effect.GetVariableByName("World").AsMatrix().SetMatrix(world);
effect.GetVariableByName("Texture").AsResource().SetResource(model.TextureShaderView);
effect.GetTechniqueByName("Render").GetPassByIndex(0).Apply();
if (model.Mesh != null)
{
model.Mesh.Setup(view.Device10, view.Content.Acquire<InputLayout>(
new Content.VertexStreamLayoutFromEffect
{
Signature10 = effect.GetTechniqueByIndex(0).GetPassByIndex(0).Description.Signature,
Layout = model.Mesh.VertexStreamLayout
}));
model.Mesh.Draw(device);
}
}
示例15: GraphicsContainer
// Constructor, which saves away all of the important information.
// We assume that the lock on the "graphics" object is held by the caller.
internal GraphicsContainer(Graphics graphics)
{
// Push this container onto the stack.
this.graphics = graphics;
next = graphics.stackTop;
graphics.stackTop = this;
// Save the graphics state information.
clip = graphics.Clip;
if(clip != null)
{
clip = clip.Clone();
}
compositingMode = graphics.CompositingMode;
compositingQuality = graphics.CompositingQuality;
interpolationMode = graphics.InterpolationMode;
pageScale = graphics.PageScale;
pageUnit = graphics.PageUnit;
pixelOffsetMode = graphics.PixelOffsetMode;
renderingOrigin = graphics.RenderingOrigin;
smoothingMode = graphics.SmoothingMode;
textContrast = graphics.TextContrast;
textRenderingHint = graphics.TextRenderingHint;
if (graphics.transform == null)
{
transform = null;
}
else
{
transform = Matrix.Clone(graphics.transform);
}
}