Winging it with Pegasus on Your next Imaging Software Project

By Mike Gold Nov 24 2006
This is a review of the new Pegasus ImagXpress 8 for Windows Forms. The review describes my experience with the product and demonstrates a few of its features.
    • Like
    • Love It
    • Awesome
    • Interesting
    • It's Okay
    • Thumbs Down
  • 10.8k
  • 0

 

Introduction

Recently I had the opportunity to work on a .NET consulting project for a client that involved photographing tourists going into the empire state building.  The project had previously been outsourced, but the offshore company didn't fulfill the client’s requirements, so we attempted to bring the project to fruition.  The project required professional image processing software to process the camera pictures, and we elected to use Pegasus Imaging.  The Pegasus components allowed us to bring images into the camera’s computer memory and process them.  Pegasus has just released for review their latest product: ImagXpress 8 for Window Forms.  The ImagXpress 8 library is thoroughly ".NET friendly"  supporting both 2003 and 2005.   The .NET assemblies have libraries for processing images, extracting images from cameras, printing images,  thumbnailing images, and annotating images.  Underlying all of the assemblies are Pegasus's powerful COM components for professional image processing.

Installation

Installation is fairly painless.  A wizard guides you through the process and installs the components for you.  The components will show up in Visual Studio 2005 and Visual Studio 2003 in your toolbox.  Also Pegasus integrates their help into Visual Studio during installation so you can easily access information on the components from the help menu of the Visual Studio IDE.

Description of Components

Pegasus's Imaging Toolkit is packed full of features.  Below is a description of each of the components and their applications:

ImageXView - This is the core component for viewing images inside a Windows Form.  Using this control, you can load images with all different kinds of popular imaging formats (such as Raw, pdf, jpeg, jbig2, tiff, pic) and view them inside of .NET.

ImagXpress - Used for handling licensing information for ImagXpress

Processor - This component is the core component of ImagXpress and is used to process images (resizing, color manipulation, red-eye removal, resolution reduction, cropping, and more)

NotateXpress - This component gives you the ability to annotate images.

PICPrintPro - this component gives you the ability to perform printing with ImagXpress.  Pegasus claims that you can use this component to print text, graphics and bitmaps on any printer installed on a system as well as to print directly to a file.

PICTwainPro – this component enables you to perform standard TWAIN image acquisition and data source selection.  It supports multiple image transfers, and file export including BMP, JPEG, and TIFF files as well as FTP transfer of file exports.

ThumbnailXpress - an independent component that allows you to view thumbnail images, thumbnails from pdfs, and asynchronous thumbnail generations from your image files.

Using ImagXpress

Designing with ImagXpress seems like a typical .NET experience.  Simply drag and drop the components on the form you want to use and implement their methods and properties.  With ImagXpress,  I was able to quickly throw together a powerful Image Processing Application that could manipulate an image in various ways beyond the capabilities of the existing .NET.  In our whipped up application we were able to add image processing features such as embossing, blurring, solarization, cropping, contrast adjustment and more with just a few lines of code.

Figure 5 - Pegasus Image Processing App.

In figure 5, we clicked the Load button and loaded our image into the ImageXView control.  The ImageXView control lets us view an ImageX class (similar to an Image class with lots of x-tra features) and the Processor class lets us process the ImageX class.

Listing 1 shows the code for initially loading our image into the ImageXView and creating a Processor to process the image.  It is important to make a copy of the image after loading it, so that you can always revert the view back to the original image state. Note how few lines of code we needed to write to get this to happen.

Listing 1 - Loading an Image into the Pegasus ImageXView

private void btnLoadImage_Click(object sender, System.EventArgs e)
 {

//  Load an image into the ImageXView
    LoadImageFromFile();

// create a new Image Processor to process the image contained in the ImageXView control
   _processor = new Processor(imageXView1.Image);
 }

private void LoadImageFromFile()
 {
   openFileDialog1.FileName = "*.jpg";
   if (openFileDialog1.ShowDialog() == DialogResult.OK)
    {

   //  Load the image from a file we selected
       imageXView1.Image = ImageX.FromFile(openFileDialog1.FileName);

      //   Make a copy of the image so we can always get back to the original image state
      _oldImage = imageXView1.Image.Copy();
      _filename = openFileDialog1.FileName;
    }
}

Processing Images is also completely self-contained in methods provided by the Processor class.  In figure 6, we Embossed our image using the Emboss method in the processor class.  Embossing gives a raised effect to the image so it actually appears to have a third dimension.

Figure 6 - Embossed Image using the Processor class

In our application, embossing occurs when the user checks the check box,;if the check box is unchecked, the control reverts back to the original image.

Listing 2 - Embossing the Image

private void chkEmboss_CheckedChanged(object sender, System.EventArgs e)
 {

  if (chkEmboss.Checked)
   {
      // emboss the image through the Processor class
     _processor.Emboss();
   }
else
  {
    // revert back to the old Image
      imageXView1.Image = _oldImage.Copy();
   
     // also set the image to process back to the old image
    _processor.Image = imageXView1.Image;
   }

}

Printing with PICPrintPro

The PicPrintPro allows you to do almost anything with printing that you can think of.  PicPrintPro gives you more power over printing devices than .NET because it provides thin wrappers around the lower level access calls to printing  (such as StartPrintDoc and EndPrintDoc).  If you are writing a professional printing application with complex printing features, you will need this level of printer control.  The PicPrintPro module comes complete with its own help module.  The help module has examples and documentation for each property and method of the control.  My only complaint is that the examples are all in VB, so a C# developer like myself must translate the code snippets, and this is painstaking work.  Below is a snippet of code that sizes your image across the entire printed page using the PicPrintPro assembly.

Listing 3- Printing with Pegasus PICPrintPro

private void btnPrint_Click(object sender, System.EventArgs e)
{
  // bring up a print dialog
  picPrintPro1.PrintDialog();

   // get a device independent bitmap from the view and assign
  // it to the print control

  picPrintPro1.hDIB = (int) imageXView1.Image.ToHdib(true);

  picPrintPro1.ScaleMode = (peScaleMode) 1;

  // start the printing process
  picPrintPro1.StartPrintDoc();

    int imageWidth;
    int imageHeight;

// calculate the width of the image accounting for the margins

   imageWidth = (int) (picPrintPro1.ScaleWidth - picPrintPro1.Lmargin);
   imageHeight = (int) (picPrintPro1.ScaleHeight - picPrintPro1.TMargin - picPrintPro1.BMargin);

// print the picture to the printer

   picPrintPro1.PrintDIB (picPrintPro1.Lmargin, picPrintPro1.TMargin, imageWidth, imageHeight, 0, 0, 0, 0, true);

// complete the printing process

   picPrintPro1.EndPrintDoc();
}

}

In Listing 3, the print method brings up a print dialog so we can adjust our printer settings before printing.  Next, the print method gets the image from our ImageXView control using a device-independent bitmap.  The height and width of the picture on the printed page are calculated using the PicPrintPro control. We want to make the image fit the entire page, so we set the image width and height to the entire page scale minus some margin values.  Finally, we print the image by calling the PrintDib method of the picPrintPro1 control. All in all, it’s fairly simple to print using the PicPrintPro print library. A minor inconvenience is that the print control could have been more object-oriented.  For example, instead of calling a PrintDialog method, we would prefer the .NET version of this control which gives you a PrintDialog object that you can manipulate.  I'm guessing that a lot of these less object-oriented methods are carryovers from the ActiveX controls in previous versions of the product. Speaking of ActiveX and carryovers from COM, don't forget to call Dispose on this control, or you will get memory leaks.  I don't want to give you the wrong impression : if you are writing professional printing applications for heavy-duty printers such as ZEBRA products or device-specific printers that often require binary and text print streams,  Pegasus's PicPrintPro is the way to go.  Although a bit more of a headache than the .NET model for printing, PicPrintPro is much more powerful in controlling the printer and data sent to the printer.

Conclusion

Initially when Pegasus had me review this product there were some installation issues, but they were quick to respond to fix these problems and the installation is now completely pain- free.  When using the older controls within the product (PrintPro and TwainPro), there will definitely be a learning curve for the .NET developer who is used to a more object-oriented approach, but with the supplied code snippets and help files, you should be well on your way to developing professional image processing software.