Skip to main content Skip to footer

Get Started with GcImaging on Linux (Video)

In this getting started video, we’ll use GcImaging on Linux to create a company logo image with rounded rectangle.

First, visit this link to license GcImaging in your application: http://help.grapecity.com/gcdocs/gcimaging/onlinehelp/webframe.html#licenseinfo.html

How to get started with GcImaging on Linux

This guide explains how to create a program that uses Documents for Imaging (GcImaging) to generate and save to disk a company logo image. GcImaging API is built for .NET Standard 2.0, and can be used with any target that supports it. In this short tutorial, we show how to build a .NET Core console application and use GcImaging in Visual Studio Code on Linux.

Step 1: Create an empty console application

Create an app using Visual Studio Code on Linux

  1. In a terminal window (you may use the terminal in Visual Studio Code), type the following commands:
$ mkdir ~/MyApp # create a directory for the application
$ cd ~/MyApp
$ dotnet new console # create a .NET Core application with MyApp.csproj and Program.cs files
  1. Open the folder of the new MyApp in Visual Studio Code.
  2. If you haven't already done so, from extensions, install Nuget Package Manager and activate it.
  3. In Visual Studio Code, press Ctrl+P to open the file command box, type > in it, find Nuget Package Manager: Add Package in the list that opens, and click it.
  4. In the search box that opens, type GrapeCity and press Enter. This brings up the list of available GrapeCity packages.
  5. Select GrapeCity.Documents.Imaging. This adds a reference to that package in your .csproj file. It looks like this:
<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>netcoreapp2.0</TargetFramework>
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="GrapeCity.Documents.Imaging" Version="2.1.0.*" />
    </ItemGroup>
</Project>

In a terminal window, type the following commands to build and run the app:

$ cd ~/MyApp
$ dotnet restore # fetches referenced packages for MyApp.csproj
$ dotnet build
$ dotnet run # runs the default app

Step 2: Add code to your application

Let’s create a new logo image for a company with GcImaging in .NET Core application. This example will draw a rounded rectangle and draw the company name text over it to generate a logo image.

  1. In the Program.cs file, include the following namespaces:
using System.IO;
using System.Drawing;
using GrapeCity.Documents.Drawing;
using GrapeCity.Documents.Text;
using GrapeCity.Documents.Imaging;
  1. Define the image parameters.
var blue = Color.FromArgb(46, 72, 132);
int pixelWidth = 350;
int pixelHeight = 100;
bool opaque = true;
float dpiX = 96;
float dpiY = 96;
float rx = 36, ry = 24;
float border = 4;
  1. Create a bitmap image object.
var bmp = new GcBitmap(pixelWidth, pixelHeight, opaque, dpiX, dpiY);
  1. Create graphics on the image.
var g = bmp.CreateGraphics(Color.Transparent); // PNG will preserve transparency
  1. Draw rounded Rectangle and fill it with desired color
var rEasy = new RectangleF(0, 0, pixelWidth, pixelHeight);
g.FillRoundRect(rEasy, rx, ry, Color.MediumPurple);
  1. Prepare the TextFormat object with text properties to add company name as text
var tf = new TextFormat()
{
          Font = Font.FromFile(Path.Combine("Resources", "Fonts", "times.ttf")),
          FontSize = 24,
          FontBold = true,
          ForeColor = Color.White
};

Note: To draw text with a Font from file, include a TTF font in the Resources folder in the project: Resources.zip

  1. Draw the text on the graphics.
g.DrawString("ACME INC.", tf, rEasy, TextAlignment.Center, ParagraphAlignment.Center, false);
  1. Save the image as PNG.
bmp.SaveAsPng("Logo.png");

Step 3: Run the application

Enter the following in a terminal window:

cd <Your Project folder>
dotnet run

That's all it takes to generate an Image using GcImaging. The ‘Logo.png’ is created in your project folder.

In order to understand in detail, how to create/modify/save an Image with advanced features and effects, refer to the GcImaging sample demo.

Try GrapeCity Documents for Imaging 30-day trial

To learn about GcImaging product architecure and features in detail, visit the GcImaging documentation.

Shilpa Sharma - Product Manager

Shilpa Sharma

Product Manager
comments powered by Disqus