The following quick start sections help you in getting started with the DsImaging library:
This quick start covers how to create an image and draw string on it in a specified font using a .NET Core or .NET Standard application. Follow the steps below to get started:
C# |
Copy Code
|
---|---|
//Create GcBitmap var bmp = new GcBitmap(1024, 1024, true, 96, 96); //Create a graphics for drawing GcBitmapGraphics g = bmp.CreateGraphics(); |
Add the following code to draw a rectangle using the RectangleF class, and then add text to it using the DrawString method of GcBitmapGraphics class.
C# |
Copy Code
|
---|---|
//Add a radial gradient RadialGradientBrush r= new RadialGradientBrush(Color.Beige, Color.RosyBrown, new PointF(0.5f, 0.5f), true); //Draw a rectangle var rc = new RectangleF(0, 0, bmp.Width, bmp.Height); //Fill the rectangle using specified brush g.FillRectangle(rc, r); // Create a text format for the "Hello World!" string: TextFormat tf = new TextFormat(); //Pick a font size, color and style tf.FontSize = 80; tf.FontStyle = FontStyle.BoldItalic; tf.ForeColor = Color.Chocolate; //Draw the string (text) g.DrawString("Hello World!", tf, rc, TextAlignment.Center, ParagraphAlignment.Center, false); |
Save the image using SaveAsJpeg method of the GcBitmap class.
C# |
Copy Code
|
---|---|
//Save bitmap as JPEG image bmp.SaveAsJpeg("HelloWorld.jpg"); |
This quick start covers how to load an existing image, modify and save it using a .NET Core or .NET Standard application. Follow the steps below to get started:
C# |
Copy Code
|
---|---|
//Create GcBitmap var bmp = new GcBitmap(); var fs = new FileStream(Path.Combine("puffins-small.jpg"), FileMode.Open, FileAccess.ReadWrite); //Load image bmp.Load(fs); |
C# |
Copy Code
|
---|---|
//Create a graphics for drawing GcBitmapGraphics g = bmp.CreateGraphics(); // Create a text format for the string: TextFormat tf = new TextFormat(); // Pick a font size, color and style tf.FontSize = 10; tf.ForeColor = Color.Red; tf.FontStyle = FontStyle.BoldItalic; //Draw the string (text) g.DrawString("Penguins", tf, new PointF(10, 10)); |
Save the image using SaveAsJpeg method of the GcBitmap class.
C# |
Copy Code
|
---|---|
//Save bitmap bmp.SaveAsJpeg("NewImage.jpg"); |