本文整理汇总了C#中Graphics类的典型用法代码示例。如果您正苦于以下问题:C# Graphics类的具体用法?C# Graphics怎么用?C# Graphics使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Graphics类属于命名空间,在下文中一共展示了Graphics类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Draw
public override void Draw(Graphics gr)
{
if (Ready)
{
gr.DrawRectangle(Pens.Green, Left, Top, Right, Bottom);
}
}
开发者ID:,项目名称:,代码行数:7,代码来源:
示例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.");
}
}
开发者ID:aspose-imaging,项目名称:Aspose.Imaging-for-.NET,代码行数:30,代码来源:AddWatermarkToImage.cs
示例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);
}
开发者ID:HeaHDeRTaJIeC,项目名称:OOP-OSiSP-Projects,代码行数:7,代码来源:POLYLINES.cs
示例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();
}
}
开发者ID:aspose-imaging,项目名称:Aspose.Imaging-for-.NET,代码行数:34,代码来源:DrawingArc.cs
示例5: Start
// Use this for initialization
void Start()
{
curve = new Curve();
graphics = new Graphics();
graphics.verticesDrawer = verticesDrawer;
}
开发者ID:inoook,项目名称:uGUICanvasTools,代码行数:8,代码来源:PointToCurveDraw.cs
示例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);
}
开发者ID:olofn,项目名称:db_public,代码行数:29,代码来源:BorderBox.cs
示例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;
}
开发者ID:zenmumbler,项目名称:GranZero,代码行数:25,代码来源:RigidBody.cs
示例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);
}
开发者ID:gitter-badger,项目名称:blimey,代码行数:31,代码来源:CylinderPrimitive.cs
示例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);
}
开发者ID:krikelin,项目名称:LerosClient,代码行数:12,代码来源:CssLineBox.cs
示例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;
}
}
}
开发者ID:Gordon-from-Blumberg,项目名称:Piczard.Examples,代码行数:33,代码来源:MyInheritedFilter.cs
示例11: Render
public virtual void Render(Graphics g)
{
for (int i = 0; i < _Particles.Count; i++)
{
_Particles[i].Render(g);
}
}
开发者ID:DJSymBiotiX,项目名称:MX-Engine,代码行数:7,代码来源:ParticleEffect.cs
示例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
}
开发者ID:aspose-imaging,项目名称:Aspose.Imaging-for-.NET,代码行数:27,代码来源:DrawingRectangle.cs
示例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));
}
开发者ID:pmprog,项目名称:OpenXCOM.Tools,代码行数:7,代码来源:Type6File.cs
示例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);
}
}
开发者ID:ChristianMarchiori,项目名称:DeadMeetsLead,代码行数:27,代码来源:InterfaceRenderer10.cs
示例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);
}
}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:34,代码来源:GraphicsContainer.cs
示例16: 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
}
开发者ID:aspose-imaging,项目名称:Aspose.Imaging-for-.NET,代码行数:30,代码来源:DrawingUsingGraphics.cs
示例17: Restore
// Restore a graphics object back to the state of this container.
// We assume that the lock on the "graphics" object is held by the caller.
internal void Restore(Graphics graphics)
{
// Bail out if the container applies to something else.
if(graphics != this.graphics)
{
return;
}
// Make sure that we are on the stack, and pop it and all
// of the items above it. Bail out if not on the stack.
GraphicsContainer container = graphics.stackTop;
while(container != null && container != this)
{
container = container.next;
}
if(container == null)
{
return;
}
graphics.stackTop = next;
// Restore the "graphics" object to its previous state.
graphics.Clip = clip;
graphics.CompositingMode = compositingMode;
graphics.CompositingQuality = compositingQuality;
graphics.InterpolationMode = interpolationMode;
graphics.PageScale = pageScale;
graphics.PageUnit = pageUnit;
graphics.PixelOffsetMode = pixelOffsetMode;
graphics.RenderingOrigin = renderingOrigin;
graphics.SmoothingMode = smoothingMode;
graphics.TextContrast = textContrast;
graphics.TextRenderingHint = textRenderingHint;
graphics.Transform = transform;
}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:37,代码来源:GraphicsContainer.cs
示例18: PrintPageEventArgs
public PrintPageEventArgs(Graphics graphics, Rectangle marginBounds, Rectangle pageBounds, PageSettings pageSettings)
{
Graphics = graphics;
MarginBounds = marginBounds;
PageBounds = pageBounds;
PageSettings = pageSettings;
}
开发者ID:asfungithub,项目名称:sysdrawing-coregraphics,代码行数:7,代码来源:PrintPageEventArgs.cs
示例19: Run
public static bool Run(Graphics graphPort, Bitmap dstBitmap, Bitmap srcBitmap, Rectangle frame, int iterations)
{
IntPtr realDC = graphPort.GetHdc();
//IntPtr hDCDst = Graphics.FromImage(dstBitmap).GetHdc(true);
IntPtr hDCDst = Graphics.FromImage(dstBitmap).GetHdc();
int XDst = 0;
int YDst = 0;
int nDstW = dstBitmap.Width;
int nDstH = dstBitmap.Height;
//IntPtr hDCSrc = Graphics.FromImage(srcBitmap).GetHdc(true);
IntPtr hDCSrc = Graphics.FromImage(srcBitmap).GetHdc();
int XSrc = 0;
int YSrc = 0;
int nSrcW = srcBitmap.Width;
int nSrcH = srcBitmap.Height;
//bool success = StretchBlt(realDC, frame.Left, frame.Top, frame.Width, frame.Height, hDCSrc, 0, 0, nDstW, nDstH, SRCCOPY);
for (int i = iterations; i >= 1; i--)
{
BLENDFUNCTION blender = new BLENDFUNCTION(AC_SRC_OVER, 0, (byte)(255 / i), 0);
if (!AlphaBlend(hDCDst, XDst, YDst, nDstW, nDstH,
hDCSrc, XSrc, YSrc, nSrcW, nSrcH, blender))
return false;
bool success = StretchBlt(realDC, frame.Left, frame.Top, frame.Width, frame.Height, hDCDst, 0, 0, nDstW, nDstH, SRCCOPY);
}
return true;
}
开发者ID:Wiladams,项目名称:NewTOAPIA,代码行数:31,代码来源:AlphaFade.cs
示例20: Entity_SkyBox
public Entity_SkyBox(Graphics.Entity.Model model)
{
m_model = model;
m_position = new Vector3(0.0f, 0.0f, 0.0f);
m_scale = new Vector3(10.0f, 10.0f, 10.0f);
m_rotation = Vector3.Zero;
}
开发者ID:SamOatesUniversity,项目名称:Year-2---Game-Software-Development---Out-Of-Scope,代码行数:7,代码来源:Entity_SkyBox.cs
注:本文中的Graphics类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论