CodeCarvings Piczard V1.2 Help
How Piczard Works
Send Feedback
Piczard Fundamentals - Core > How Piczard Works

Glossary Item Box

This is a basic tutorial, designed to help you get started using Piczard.

This tutorial illustrates programmatic image processing features of Piczard (Core).
If you are interested in interactive web features, please refer to:

 

Before starting this tutorial it is necessary:

  1. To download and install Piczard on your PC 
  2. If you don't have an empty Microsoft Visual Studio project, create a new one (for example a new ASP.NET project)
  3. To add a reference to the Piczard assembly (CodeCarvings.Piczard.dll) to the project.

 

CONTENTS

  1. Piczard: The basics
  2. Complex image processing
  3. Customize the image format of output images
  4. Working with different image resolutions (DPI) and unit of measure

 

 

1. Piczard: The basics 

Please see the Example A.101 - "Use a single image filter".

The key element that allows to process images with Piczard is the Filter (represented by the abstract class ImageProcessingFilter).

There are several Filters available in Piczard, such as ResizeConstraint (to automatically resize images), or CropConstraint (to crop images).
Many other Filters can be created by inheriting from the ImageProcessingFilter class (for more information: How To Develop A Custom Image Processing Filter).


Figure 1: How works an ImageProcessingFilter.

 

FixedResizeConstraint is one of the 2 filters available in Piczard that allow the automatic resize of images based on size constraints.
In order to instantiate this filter, it is necessary to provide the size (width and height) of the image to generate.

The following code allows to instantiate a filter able to generate fixed size images (500 x 300 pixels):

Copy Code
FixedResizeConstraint resizeConstraint = new FixedResizeConstraint(500, 300);

Once the filter has been instantiated, it's ready to be used to process an image
For example, by invoking the SaveProcessedImageToFileSystem method.
The following code process the file "Source.jpg", and then save the result (an image having size 500x300 pixels) in a file with the name "Output.jpg":

Copy Code
FixedResizeConstraint resizeConstraint = new FixedResizeConstraint(500, 300);
resizeConstraint.SaveProcessedImageToFileSystem(
"Source.jpg", "Output.jpg");

 

In this case, the SaveProcessedImageToFileSystem method uses default values for the following parameters:

Naturally  it is possible to customize these and other parameters.

 

 

2. Complex image processing 

Please see the Example A.102 - "Use multiple image filters".

With Piczard it's possible to apply more ImageProcessingFilters in sequence to an image.
In order to do this, it is necessary to setup an instance of the ImageProcessingFilterCollection class.
This class is a container where you can add an unlimited number of filters..

The filters are applied in sequence, during the image processing phase.

Figure 2: Multiple filters using the ImageProcessingFilterCollection class.

 

The following example creates an ImageProcessingFilterCollection class. Afterwards the code adds:

  1. A filter to resize the image to 500 x 300 pixels (please see the above examples)
  2. A filter to transform the image to grayscale

Finally, the SaveProcessedImageToFileSystem method is invoked in order to apply all the filters and generate the image file "Output.jpg".

Copy Code
ImageProcessingFilterCollection myFilters = new ImageProcessingFilterCollection();
myFilters.Filters.Add(
new FixedResizeConstraint(500, 300));
myFilters.Filters.Add(Filters.Colors.DefaultColorFilters.Grayscale);
myFilters.SaveProcessedImageToFileSystem(
"Source.jpg", "Output.jpg");

Please note that all the filters are applied only when one of the following methods is invoked:

 

 

3. Customize the image format of output images

Please see the Example A.103 - "Load & save image files".

Piczard handles image formats (Jpeg, Png, Bmp, etc...) by using classes that inherits from FormatEncoderParams.
For example, the JpegFormatEncoderParams  class identify the Jpeg image format and its settings.

The following code allows to create an instance of the JpegFormatEncoderParams class, able to save Jpeg images with Quality 60%:

Copy Code
JpegFormatEncoderParams formetParams = new JpegFormatEncoderParams(60);

The FormatEncoderParams classes can be passed as parameter to methods that can save images:

Copy Code
new FixedResizeConstraint(500, 300).SaveProcessedImageToFileSystem("Source.jpg", "Output.jpg", new JpegFormatEncoderParams(60));

If you want to save Png images, you can use the following code:

Copy Code

new FixedResizeConstraint(500, 300).SaveProcessedImageToFileSystem("Source.jpg", "Output.png", new PngFormatEncoderParams());

 

 

4. Working with different image resolutions (DPI) and unit of measure

Please see the Example A.106 - "Working with different image resolutions".

Piczard allows to work with different image resolutions (DPI) and unit of measure.

The Piczard default settings are:

 

The resolution of images generated by Piczard can be changed in two ways:

  1. By passing the "outputResolution" parameter to one of the following methods of the ImageProcessingFilter class:
  2. By setting the OutputResolution property of the ImageProcessingJob class.
    (ImageProcessingJob is a base class that allows to handle various image processing options such as Output Resolution or Background Color. For more information please see: Image Processing Job)

The following example code allows to generate images with fixed size 500 x 300 pixels at 300 DPI:

Output image: Fixed size (500px x 300px) - 300DPI - Jpeg image format Copy Code
ImageProcessingJob job = new ImageProcessingJob();
job.Filters.Add(
new FixedResizeConstraint(500, 300));
job.OutputResolution = 300F;
job.SaveProcessedImageToFileSystem(
"Source.jpg", "Output.jpg");

 

Many of the Piczard filters support unit of measure different from the default one (Pixel).
For example, the following code allows to generate a fixed size image 50mm x 30.5mm at 300 DPI:

Output image: Fixed size (50mm x 30.5mm) - 300DPI - Jpeg image format Copy Code
ImageProcessingJob job = new ImageProcessingJob();
job.Filters.Add(
new FixedResizeConstraint(GfxUnit.Mm, 50F, 30.5F));
job.OutputResolution = 300F;
job.SaveProcessedImageToFileSystem(
"Source.jpg", "Output.jpg");

Please note that unit of measure different from Pixel (such as Inch or Mm), are relative to the image resolution (DPI).
For example, an image having size 1 inch x 1 inch is equivalent to an image having size 300 x 300 pixels if the resolution is 300 DPI.
While, if the resolution is 96 DPI, then the size 1 inch x 1 inch is equivalent to 96 x 96 pixels.

  • The CropConstraint and ResizeConstraint filters support unit of measure different from Pixel.
    The size parameters of that classes are referred to the output image resolution (ImageProcessingJob.OutputResolution) and they have nothing to do with the original resolution of the source image.
  • The ImageCrop filter supports only the Pixel graphic unit.
    However, through the static method ImageCrop.Calculate, it is possible to easily translate values expressed in different unit of measure. Example:
    ImageCrop pixelImageCrop = ImageCrop.Calculate(GfxUnit.Inch, new RectangleF(0F, 0F, 1.2F, 2.4F), 300F);
©2013 Sergio Turolla. All Rights Reserved.