Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

How to Display, Save, and Annotate 100+ Image Formats in Silverlight Clients

7 Jan 2013 1  
With minimal effort you can use LEADTOOLS V17 to load and save over 100 file formats, manipulate images with advanced image processing, and implement annotations directly within a Silverlight client application replacing the need for calls to an external server.

This article is in the Product Showcase section for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers.

Introduction

LEAD Technologies has been the prominent provider of digital imaging tools since 1990. Its award-winning LEADTOOLS family of toolkits helps developers integrate raster, document, medical, multimedia, vector and Internet imaging into their applications quickly and easily. Using LEADTOOLS for your imaging requirements allows you to spend more time on user interface and application-specific code, expediting your development cycle and increasing your return on investment.

The LEADTOOLS Silverlight Imaging SDK is included with all products in the LEADTOOLS Document and Medical Imaging product groups. LEADTOOLS provides Silverlight developers the ability to load, display, process, and save many image formats not intrinsic to the Silverlight framework such as JPEG 2000, TIFF, JBIG2 and DICOM. Because of the 100% pure, managed Silverlight binaries, images can be processed and annotated directly within the Silverlight application without external dependencies or server calls.

LEADTOOLS comes with several viewing components including an Image Viewer, Image List and Pan Window. The viewer is equipped with many automated interactive tools, making it easy for developers to implement scroll, pan, scale, zoom and mag-glass features to generate an elegant user experience. Effortless navigation through high resolution and multipage images can be achieved with the Pan Window and Image List controls.

Silverlight based Document Imaging applications are also possible with LEADTOOLS. Popular bi-tonal compression formats such as CCITT, FAX, and JBIG2 are included. To maximize readability, compression, and accuracy for OCR and Barcode recognition, developers can clean images by deskewing and removing lines, hole punches, borders and more. Adding Annotations and Markup to your Silverlight application is a cinch with LEADTOOLS’ fully automated annotations. Load, save and edit popular annotation types including line, ruler, polygon, curve, note, highlight, redaction and more.

In this article, we will introduce you to the key features of the new Silverlight classes and provide you with a step-by-step tutorial implementing them. Try it out for yourself by downloading a fully functional evaluation SDK from the links provided below the tutorial.

Key Features

  • 100% pure, managed Silverlight binaries
  • Load and save over 100 image formats including PDF, JPEG2000, FAX, CCITT, JBIG2 and TIFF
  • Display images in a high level viewer control equipped with interactive features such as scroll, pan, scale, mag-glass and zoom
  • Utilize Image List and Pan Window controls to effortlessly navigate through multipage and high resolution images
  • Perform over 200 advanced image processing functions including document clean up
  • Apply instantaneous image transformations with Pixel Shaders such as invert, shutters, sharpen, edge detection, brightness and contrast
  • Implement Annotations and markup to load, save, and edit popular annotation types including ruler, polygon, curve, highlight and redaction
  • Load, view, process and save DICOM Data Sets
  • Display and process 12/16 bit extended grayscale images with Window Level, Multi-scale Enhancement, Tissue Equalization and more
  • Use WCF to extend functionality to include advanced features like OCR and Barcode

Environment

The LEADTOOLS Silverlight class library includes binaries for Silverlight 3 and 4 for the development of rich-client web and desktop applications within Visual Studio 2008 and 2010.

The Code

In addition to our powerful viewing components, LEADTOOLS ships with several utility classes including a menu system. To use these, you will need to add a namespace for Leadtools.Windows.Controls and Leadtools.Silverlight.Demos. Here is the XAML code for implementing a simple menu and viewer:

<UserControl x:Class="LeadtoolsSilverlightExample.MainPage"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   xmlns:menu="clr-namespace:Leadtools.Silverlight.Demos;assembly=Leadtools.Silverlight.Demos"
   xmlns:Leadtools_Windows_Controls="clr-namespace:Leadtools.Windows.Controls;assembly=Leadtools.Windows.Controls" >
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto"></RowDefinition>
      <RowDefinition></RowDefinition>
    </Grid.RowDefinitions>
    <menu:Menu x:Name="MainMenu" Background="#EEEEEE" Grid.Row="0">
      <menu:MenuItem Header="File">
        <menu:MenuItem Header="Open..." x:Name="FileOpen" Click="FileOpen_Click"/>
        <menu:MenuItem Header="Save..." x:Name="FileSave" Click="FileSave_Click"/>
      </menu:MenuItem>
    </menu:Menu>
    <Grid  x:Name="LayoutRoot" Grid.Row="1">
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="10*"></ColumnDefinition>
        <ColumnDefinition Width="Auto"></ColumnDefinition>
      </Grid.ColumnDefinitions>
      <Leadtools_Windows_Controls:RasterImageViewer x:Name="viewerControl" Grid.Column="0" />
    </Grid>
  </Grid>
</UserControl>

LEADTOOLS includes 100% pure Silverlight binaries for loading and saving over 100+ image formats. Image read and write support is handled through the RasterCodecs class. This library is also capable of reading and writing metadata tags from files like TIFF and EXIF. To save the developer space and minimize the deployment footprint, each format is handled by its own codec (e.g. Leadtools.Codecs.Bmp.dll, Leadtools.Codecs.J2k.dll, Leadtools.Codecs.Tif.dll, etc.). Below is an example of how to load and display an image the LEADTOOLS RasterImageViewer control and also how to save it back out as a JPEG 2000 stream:

private void FileOpen_Click(object sender, RoutedEventArgs e)
{
   OpenFileDialog ofd = new OpenFileDialog();
   if (ofd.ShowDialog() == true)
   {
      using (Stream stream = ofd.File.OpenRead())
      {
         RasterCodecs codecs = new RasterCodecs();
         viewerControl.Image = codecs.Load(stream);
      }
   }
}
 
private void FileSave_Click(object sender, RoutedEventArgs e)
{
   RasterImageFormat format = RasterImageFormat.J2k;
   int bitsPerPixel = 24;
 
   SaveFileDialog sfd = new SaveFileDialog();
   sfd.Filter = "JPEG2000 Stream (*.j2k)|*.j2k";
   if (sfd.ShowDialog() == true)
   {
      using (Stream stream = sfd.OpenFile())
      {
         RasterCodecs codecs = new RasterCodecs();
         codecs.Save(viewerControl.Image, stream, format, bitsPerPixel);
      }
   }
}

LEADTOOLS SDKs come with hundreds of image processing functions to accomplish virtually any task with the image at hand. We have all the basic functionality one would expect (e.g. rotate, flip, etc.) but have developed many advanced algorithms for mathematical calculations, geometric transformations, color operations, region-of-interest and artistic effects. We also have a number of functions for specialized fields such as document image cleanup (deskew documents and checks, remove dots, lines, hole punches, etc.) and medical (Window Level, Multiscale Enhancement, Tissue Equalize). Rather than lumping hundreds of functions into a single object we have separated each image processing operation into a separate command class to give the developer more control over organization and deployment footprint. Below is a simple example of how to adjust a few color properties of an image:

ChangeIntensityCommand cmdIntensity = new ChangeIntensityCommand(250);
cmdIntensity.Run(viewerControl.Image);
ChangeContrastCommand cmdContrast = new ChangeContrastCommand(-750);
cmdContrast.Run(viewerControl.Image);
ChangeHueCommand cmdHue = new ChangeHueCommand(500);
cmdHue.Run(viewerControl.Image);

LEADTOOLS-Silverlight/image001.jpg

Finally, LEADTOOLS makes it simple to add high level, customizable, and fully automated annotation and markup support to your Silverlight client application. Within your application initialization code, simply instantiate and set up a few objects, add a toolbar, and you’re ready to start using LEAD’s automated annotations.

AnnAutomationManager manager = new AnnAutomationManager();
manager.CreateDefaultObjects();
manager.CreateToolBar();
 
LayoutRoot.Children.Add(manager.ToolBar);
 
manager.ToolBar.Orientation = Orientation.Vertical;
manager.ToolBar.HorizontalAlignment = HorizontalAlignment.Center;
manager.ToolBar.UpdateLayout();
Grid.SetColumn(manager.ToolBar, 1);

_automation = new AnnAutomation(manager, viewerControl);

LEADTOOLS-Silverlight/image002.jpg

Conclusion

LEADTOOLS provides developers with access to the world’s best performing and most stable imaging libraries in an easy-to-use, high-level programming interface enabling rapid development of business-critical applications. The new version 17 will allow Silverlight developers to extend image format support, process and annotate images in rich client web applications.

Silverlight is only one of the many technologies LEADTOOLS has to offer. For more information on our other products, be sure to visit our home page and download a free fully functioning evaluation SDK, and take advantage of our free technical support during your evaluation.

Download the Full Example

You can download a fully functional demo which includes the features discussed above as well as some image processing and interactive viewing features. To run this example you will need the following:

LEADTOOLS also includes binaries and examples for Silverlight 3. To use these, you will need Visual Studio 2008 and Microsoft Silverlight 3 Tools for Visual Studio 2008.

If you want to try LEADTOOLS Document Imaging before making a purchasing decision, you can download the LEADTOOLS free 60 day evaluation.

Support

Need help getting this sample up and going? Contact our support team for free technical support! For pricing or licensing questions, you can contact our sales team (sales@leadtools.com) or call us at 704-332-5532.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here