Take the following steps to start a project and to add some code that will load and display an image into the LEADTOOLS Silverlight Control.
In the "Solution Explorer" window, right-click on the "References" folder for the Silverlight project and select "Add Reference…" from the context menu. In the "Add Reference" dialog box, browse to the "<LEADTOOLS_INSTALLDIR>\Bin\Silverlight" or "<LEADTOOLS_INSTALLDIR>\Bin\Silverlight4" folder (depending on your target Silverlight version), and select the following DLLs:
Click the Select button and then press the OK button to add the above DLLs to the application.
Open the MainPage.xaml file and copy the below XAML code into the editor:
[XAML]
<UserControl x:Class="Load_And_Display.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Leadtools_Windows_Controls="clr-namespace:Leadtools.Windows.Controls;assembly=Leadtools.Windows.Controls"
Width="800" Height="800">
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel Orientation="Vertical" >
<Leadtools_Windows_Controls:RasterImageViewer x:Name="viewerControl" SizeMode="Normal" Width="500" Height="500"></Leadtools_Windows_Controls:RasterImageViewer>
<Button Name="myButton" Content="Load" FontSize="30" Click="Button_Click"></Button>
</StackPanel>
</Grid>
</UserControl>
Switch to MainPage.xaml code view (right-click Page.xaml in the solution explorer then select View Code) and add the following lines at the beginning of the file:
Imports System.IO
Imports Leadtools
Imports Leadtools.Codecs
using System.IO;
using Leadtools;
using Leadtools.Codecs;
Add the following class function:
Private Sub Button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
Try
Dim ofd As OpenFileDialog = New OpenFileDialog()
If ofd.ShowDialog() = True Then
Dim fileStream As FileStream = ofd.File.OpenRead()
Try
Dim codecs As RasterCodecs = New RasterCodecs()
viewerControl.Image = codecs.Load(fileStream)
Finally
fileStream.Dispose()
End Try
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
private void Button_Click(object sender, RoutedEventArgs e)
{
try
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == true)
{
using (FileStream fileStream = ofd.File.OpenRead())
{
RasterCodecs codecs = new RasterCodecs();
viewerControl.Image = codecs.Load(fileStream);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
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.
Products |
Support |
Feedback: Loading and displaying an image in Silverlight |
Introduction |
Help Version 19.0.2017.6.21
|
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.