Document Solutions for Imaging
Getting Started / Quick Start
In This Topic
    Quick Start
    In This Topic

    The following quick start sections help you in getting started with the DsImaging library:

    Create and Save an Image

    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:

    1. Create an instance of GcBitmap class
    2. Draw and fill a rectangle
    3. Save the image

    Image with 'Hello World' text created in GcImaging

    Step 1: Create an instance of GcBitmap class

    1. Create a new application (.NET Core Console App\Windows Forms App) and add the references.
    2. Include the following namespaces
      • using GrapeCity.Documents.Imaging;
    3. Create a new image using an instance of GcBitmap class, through code.
      C#
      Copy Code
      //Create GcBitmap
      var bmp = new GcBitmap(1024, 1024, true, 96, 96);
      //Create a graphics for drawing
      GcBitmapGraphics g = bmp.CreateGraphics();
      

    Back to Top

    Step 2: Draw and fill a rectangle

    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);
    

    Back to Top

    Step 3: Save the image

    Save the image using SaveAsJpeg method of the GcBitmap class.

    C#
    Copy Code
    //Save bitmap as JPEG image
    bmp.SaveAsJpeg("HelloWorld.jpg");
    
    Back to Top

    Load and Modify an Image

    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:

    1. Load an existing image
    2. Modify the image
    3. Save the image

    Step 1: Load an existing image

    1. Create a new application (.NET Core Console App\Windows Forms App) and add the references.
    2. Include the following namespace
      • using GrapeCity.Documents.Imaging;
    3. Load an existing image using Load method of the GcBitmap class.
      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);
      
    Back to Top

    Step 2: Modify the image

    1. Add the following code that to add a text using the DrawString method of GcBitmapGraphics class to draw string.
      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));
      
    Back to Top

    Step 3: Save the image

    Save the image using SaveAsJpeg method of the GcBitmap class.

    C#
    Copy Code
    //Save bitmap
    bmp.SaveAsJpeg("NewImage.jpg");
    
    Back to Top