Search code examples
c#wpfimageviewer

Displaying an Atalasoft Image


I have an AtalaImage class loaded with a TIFF image instance and I want to display the image in a WPF AtalaImageViewer control or even the stock standard .Net WPF Image control.

It should be simply but I can't figure out how to do this, can someone please help.

Thanks


Solution

  • You should be able to copy Atalasoft binary to MemoryStream and read with BitmapSource class.

    Something like this. (I have not tested)

        var atalaIamge = new AtalaImage(100, 100, PixelFormat.Pixel32bppBgra);
    
        var imageData = atalaIamge.ToByteArray(new PngEncoder())
        var image = new BitmapImage();
        using (var mem = new MemoryStream(imageData))
        {
            mem.Position = 0;
            image.BeginInit();
            image.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
            image.CacheOption = BitmapCacheOption.OnLoad;
            image.UriSource = null;
            image.StreamSource = mem;
            image.EndInit();
        }
    
        wpfImageControl.Source = image;