Take the following steps to start a project and to add some code that will load,display and zoom in/out an image into the LEADTOOLS WinRT Control.
In the Solution Explorer window, right-click on the References folder for the project and select Add Reference... from the context menu. In the Reference Manager dialog box, select Leadtools.Controls from the Windows=>Extension list.
Browse to the <LEADTOOLS_INSTALLDIR>\Bin\WinRT\ folder (depending on your target platform), and select the following .WINMD files:
[XAML]
<Page
x:Class="ZoomIn_ZoomOut.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ZoomIn_ZoomOut"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:custom="using:Leadtools.Controls"
mc:Ignorable="d">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<StackPanel>
<Button x:Name="_loadButton" Click="_loadButton_Click">Load</Button>
<Button x:Name="_zoomIn" Click="_zoomIn_Click">Zoom In</Button>
<Button x:Name="_zoomOut" Click="_zoomOut_Click">Zoom Out</Button>
<TextBlock x:Name="_text"/>
<custom:RasterImageViewer x:Name="_viewer" Source="Assets/Ocr1.bmp" Width="500" Height="500" PropertyChanged="_viewer_PropertyChanged"/>
</StackPanel>
</Grid>
</Page>
Double-click on the "Package.appxmanifest" file. On the Declarations tab, add the "File Open Picker as a Supported Declaration. Also, check the "Supports any file type" checkbox.
[C#]
using Windows.Storage;
using Windows.Storage.Pickers;
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Converters;
Add the following code to the MainPage constructor:
RasterSupport.Initialize(); // replace this with RasterSupport.SetLicense when you have a valid runtime license.
_text.Text = string.Format("Current Scale Factor : {0}%", 100);
Add the following class function:
[C#]
private async void _loadButton_Click(object sender, RoutedEventArgs e)
{
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".cmp");
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".tif");
StorageFile file = await openPicker.PickSingleFileAsync();
if (null != file)
{
try
{
//Open the file as a WinRT RandomAccessStream and create an ILeadStream from this RandomAccessStream
ILeadStream leadStream = LeadStreamFactory.Create(file);
using (IDisposable disposable = leadStream as IDisposable)
{
using (RasterCodecs codecs = new RasterCodecs())
{
_viewer.Image = await codecs.LoadAsync(leadStream);
}
}
}
catch (Exception exception)
{
string message = exception.Message;
RasterException rasterException = RasterException.FromHResult(exception.HResult);
if (rasterException != null)
message = rasterException.Message;
System.Diagnostics.Debug.WriteLine(message);
}
}
}
private void _zoomIn_Click(object sender, RoutedEventArgs e)
{
_viewer.ScaleFactor *= 1.2;
}
private void _zoomOut_Click(object sender, RoutedEventArgs e)
{
_viewer.ScaleFactor /= 1.2;
}
private void _viewer_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (string.Compare(e.PropertyName,"ScaleFactor") == 0)
{
_text.Text = string.Format("Current Scale Factor : {0:F2}%", _viewer.ScaleFactor * 100);
}
}
Build, and Run the program to test it.
Click the "Load" button, and select an image.
NOTE: if you encounter and "Invalid File Format" or "Feature Not Supported" exception, please refer to the topic Invalid File Format/Feature Not Supported.