DotImage Knowledgebase

Home : How to convert between WPF BitmapSource objects and AtalaImage
Q10156 - HOWTO: How to convert between WPF BitmapSource objects and AtalaImage

Windows Presentation Foundation (WPF) includes a BitmapSource class for loading, manipulating, and storing images.  If you want to use DotImage commands on a BitmapSource, you will need to convert between BitmapSource and AtalaImage.  This article contains code for doing that and sample code for applying commands.

Once you include the attached converters into your project, you can use this function to apply commands to a BitmapSource:

private BitmapSource ApplyCommand(ImageCommand cmd, BitmapSource bitmapSource)
{
   WPFToAtalaConverter aiAdapter =
      
new WPFToAtalaConverter(bitmapSource);   
   AtalaImage
aImg = aiAdapter.ToAtalaImage();

   ImageResults res = cmd.Apply(aImg);

   AtalaToWPFConverter wpfAdapter =
     
new AtalaToWPFConverter(res.Image);
   bitmapSource = wpfAdapter.ToBitmapSource();
  
   aImg.Dispose();
   if (!res.IsImageSourceImage) {
      res.Image.Dispose();
   }

   return bitmapSource;
}

The code for the converters is attached to this KB article.  Note that PixelFormats, Palettes, Colors, the channels of a CMYK image, and the conventions for Black and White images are different in Atalasoft Images and WPF BitmapSources.

 

In versions 8.0 and greater the PixelData property of the AtalaImage has been obsolesed. The second zip file attached to this article contains the modification to make PixelData still work.

Related Articles
No Related Articles Available.

Article Attachments
AtalaImageWPFAdapter8.0andGreater.zip
AtalaImageWPFAdapter.zip

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.

Powered By InstantKB.NET v1.3
Copyright © 2002, 2014. InstantASP Ltd. All Rights Reserved

preload preload preload