Search

Atalasoft Knowledge Base

HOWTO: How to convert between WPF BitmapSource objects and AtalaImage

Administrator
DotImage

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.

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

Details
Last Modified: Last Month
Last Modified By: Administrator
Type: HOWTO
Article not rated yet.
Article has been viewed 37 times.
Options
Also In This Category