ImageGear for .NET
Adding the Code Behind
  1. In addition to those provided by default, some Namespaces, ImageGear and .NET Framework, will need to be qualified at the top of Window1.xaml.cs. It will look like this: 
    C#
    Copy Code
    using System.IO;
    using System.Windows.Forms;
    using System.Diagnostics;
    using ImageGear;
    using ImageGear.Core;
    using ImageGear.Display;
    using ImageGear.Windows.Forms;
    using ImageGear.Windows.Controls;
    using ImageGear.Processing;
    using ImageGear.Formats;
    using ImageGear.WPF;
    using ImageGear.WPF.HDP; 
  2. Two member variables will need to be added to the class: an ImGearPage to hold the image data and an ImGearPageDisplay that will control the ways we show it. It should look as below:
    C#
    Copy Code
    ImGearPage igPage = null;
    ImGearPresentationPageDisplay igPageDisplay = null;
  3. To the constructor, just below the call to InitializeComponent, code will be added to handle the ImageGear Deployment (Runtime) licensing. This is not necessary if you are using an Evaluation or Development (Toolkit) license.
    C#
    Copy Code
    //***The SetSolutionName, SetSolutionKey and possibly the SetOEMLicenseKey 
    //methods must be called to distribute the runtime.***
    //ImGearLicense.SetSolutionName("YourSolutionName");
    //ImGearLicense.SetSolutionKey(12345, 12345, 12345, 12345);
    //Manually Reported Runtime licenses also require the following method 
    //call to SetOEMLicenseKey.
    //ImGearLicense.SetOEMLicenseKey("2.0.AStringForOEMLicensing...");
  4. The last code to be added to the constructor, below the licensing, will be to insert the HD Photo format held by the IGWPF component and to initialize the Common Formats component added earlier. It will look like this:
    C#
    Copy Code
    ImGearFileFormats.Filters.Insert(0, ImGearHDPhoto.CreateHDPhotoFormat());
    ImGearCommonFormats.Initialize();
  5. Now to add code to the OpenExecuted handler. This will simply launch the ImageGear OpenFile Dialog so we can select an image file and put it on the ImGearPageView object. The finished handler should look like:
    C#
    Copy Code
    ImGearLoadingSelection selection = ImGearWinForms.SelectLocalFileToLoad(null, "Select File");
    if (null != selection)
    {
        using (FileStream fileContent = ((ImGearLocalFile)
           selection.File).OpenToRead())
        {
            try
            {
                igPage = ImGearFileFormats.LoadPage(fileContent, 0);
            }
            catch (ImGearException ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
        if (null != igPage && null != igPage.DIB &&
            !igPage.DIB.IsEmpty())
        {
            // Create a new page display
            igPageDisplay = new ImGearPresentationPageDisplay(igPage);
            // Associate the page display with the page view
            imGearPageView1.Display = igPageDisplay;
            // Cause the page view to update
            imGearPageView1.Update();
        }
    }
  6. Add code to the Handler for the 'Zoom In' and 'Zoom Out'  Executed handlers as below:
    C#
    Copy Code
    private void ZoomInExecuted(object sender, ExecutedRoutedEventArgs e)
    {
        // Get the current zoom info  
        ImGearZoomInfo igZoomInfo = igPageDisplay.GetZoomInfo(imGearPageView1);
        // Increase the zoom  
        igZoomInfo.Horizontal.Value = igZoomInfo.Horizontal.Value * 1.25;
        igZoomInfo.Vertical.Value = igZoomInfo.Vertical.Value * 1.25;
        igZoomInfo.Horizontal.Fixed = true;
        igZoomInfo.Vertical.Fixed = true;
        // Set the new zoom values 
        igPageDisplay.UpdateZoomFrom(igZoomInfo);
        // Trigger an update, letting it know only the layout has changed.
        imGearPageView1.Update(true);
    }
    private void ZoomOutExecuted(object sender, ExecutedRoutedEventArgs e)
    {
        // Get the current zoom info  
        ImGearZoomInfo igZoomInfo = igPageDisplay.GetZoomInfo(imGearPageView1);
        igZoomInfo.Horizontal.Value = igZoomInfo.Horizontal.Value * (1 / 1.25);
        igZoomInfo.Vertical.Value = igZoomInfo.Vertical.Value * (1 / 1.25);
        igZoomInfo.Horizontal.Fixed = true;
        igZoomInfo.Vertical.Fixed = true;
        // Set the new zoom values
        igPageDisplay.UpdateZoomFrom(igZoomInfo);
        // Trigger an update, letting it know only the layout has changed.
        imGearPageView1.Update(true);
    }
  7. The three Rotate handlers under Processing:
    C#
    Copy Code
    private void ExectutedRotate90(object sender, ExecutedRoutedEventArgs e)
    {
        try
        {
            ImGearProcessing.Rotate(igPage, ImGearRotationValues.VALUE_90);
            imGearPageView1.Update();
        }
        catch (ImGearException ex)
        {
            Debug.WriteLine(ex.Message);
        }
    }
    private void ExectutedRotate180(object sender, ExecutedRoutedEventArgs e)
    {
        try
        {
            ImGearProcessing.Rotate(igPage, ImGearRotationValues.VALUE_180);
            imGearPageView1.Update();
        }
        catch (ImGearException ex)
        {
            Debug.WriteLine(ex.Message);
        }
    }
    private void ExectutedRotate270(object sender, ExecutedRoutedEventArgs e)
    {
        try
        {
            ImGearProcessing.Rotate(igPage, ImGearRotationValues.VALUE_270);
            imGearPageView1.Update();
        }
        catch (ImGearException ex)
        {
            Debug.WriteLine(ex.Message);
        }
    }
  8. Then this standard code to the ExitExecuted Handler:
    C#
    Copy Code
    private void ExitExecuted(object sender, ExecutedRoutedEventArgs e)
    {
        this.Close();
    }
  9. And finally, code the shared CanExecute handler CanExecutePageAvailable:
    C#
    Copy Code
    private void CanExectutePageAvailable(object sender, CanExecuteRoutedEventArgs e)
    {
        e.CanExecute = (null != igPage && null != igPage.DIB
            && !igPage.DIB.IsEmpty() && null != igPageDisplay);
    }
  10. You are now ready to compile and run the finished application.

 

 

 


©2014. Accusoft Corporation. All Rights Reserved.

Send Feedback