C# Graphics Library
I need to integrate some graphics methods into my C# programs. I do not need any colour graphs just black and white graphs giving me lines circles and general curves. What is the best out there?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
senthil kannanPosted Jul 25, 2006, 6:00 AM
u can go thru this code ....
just change the colors
as u likeusing
System;using
System.Drawing;using
System.Collections;//using System.ComponentModel;
using
System.Windows.Forms;using
System.Data;using
System.Drawing.Drawing2D;namespace
_2D{
///{
///{
// // Required for Windows Form Designer support //InitializeComponent();
// // TODO: Add any constructor code after InitializeComponent call //}
///{
if( disposing ){
if (components != null){
components.Dispose();
}
}
base.Dispose( disposing );}
#region
Windows Form Designer generated code ///{
// // DrawShapesForm // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 273); this.Name = "DrawShapesForm"; this.Text = "2D Example"; this.Paint += new System.Windows.Forms.PaintEventHandler(this.DrawShapesForm_Paint);}
#endregion
///[STAThread]
static void Main(){
Application.Run(
new DrawShapesForm());}
private void DrawShapesForm_Paint( object sender, PaintEventArgs e ){
// references to object we will useGraphics graphicsObject = e.Graphics;
// ellipse rectangle and gradient brushRectangle drawArea1 =
new Rectangle( 5, 35, 30, 100 );LinearGradientBrush linearBrush =
new LinearGradientBrush ( drawArea1, Color.Blue,Color.Yellow, LinearGradientMode.ForwardDiagonal);
// draw ellipse filled with a blue-yellow gradientgraphicsObject.FillEllipse( linearBrush, 5, 30, 65, 100 );
//graphicsObject.FillEllipse(linearBrush,5,150,100,150); // pen and location for red outline rectanglePen thickRedPen =
new Pen( Color.Red, 10 );graphicsObject.DrawLine(thickRedPen,40,150,40,250);
graphicsObject.DrawLine(thickRedPen,45,200,90,150);
graphicsObject.DrawLine(thickRedPen,45,200,90,250);
Rectangle drawArea2 =
new Rectangle( 80, 30, 65, 100 ); // draw thick rectangle outline in redgraphicsObject.DrawRectangle( thickRedPen, drawArea2 );
// bitmap textureBitmap textureBitmap =
new Bitmap( 10, 10 ); // get bitmap graphicsGraphics graphicsObject2 =
Graphics.FromImage( textureBitmap );
// brush and pen used throughout programSolidBrush solidColorBrush =
new SolidBrush( Color.Red );Pen coloredPen =
new Pen( solidColorBrush ); // fill textureBitmap with yellowsolidColorBrush.Color = Color.Yellow;
graphicsObject2.FillRectangle( solidColorBrush, 0, 0, 10, 10 );
// draw small black rectangle in textureBitmapcoloredPen.Color = Color.Black;
graphicsObject2.DrawRectangle( coloredPen, 1, 1, 6, 6 );
// draw small blue rectangle in textureBitmapsolidColorBrush.Color = Color.Blue;
graphicsObject2.FillRectangle( solidColorBrush, 1, 1, 3, 3 );
// draw small red square in textureBitmapsolidColorBrush.Color = Color.Red;
graphicsObject2.FillRectangle( solidColorBrush, 4, 4, 3, 3 );
// create textured brush and // display textured rectangleTextureBrush texturedBrush =
new TextureBrush( textureBitmap );graphicsObject.FillRectangle( texturedBrush, 155, 30, 75, 100 );
// draw pie-shaped arc in whitecoloredPen.Color = Color.White;
coloredPen.Width = 6;
graphicsObject.DrawPie( coloredPen, 240, 30, 75, 100, 0, 270 );
// draw lines in green and yellowcoloredPen.Color = Color.Green;
coloredPen.Width = 5;
graphicsObject.DrawLine( coloredPen, 395, 30, 320, 150 );
// draw a rounded, dashed yellow linecoloredPen.Color = Color.Yellow;
coloredPen.DashCap = DashCap.Round;
coloredPen.DashStyle = DashStyle.Dash;
graphicsObject.DrawLine( coloredPen, 320, 30, 395,150 );
}
}
}