Leadtools.Windows.Controls Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.03.25
BitmapSourceViewer Class
See Also  Members   Example 
Leadtools.Windows.Controls Namespace : BitmapSourceViewer Class





Represents a LEADTOOLS for WPF BitmapSourceViewer control for displaying an image.

Object Model


Syntax

Visual Basic (Declaration) 
<TemplatePartAttribute(Name="PART_Magnify", Type=System.Windows.Controls.Canvas)>
Public Class BitmapSourceViewer 
   Inherits ContentControl
   Implements IElement 
Visual Basic (Usage)Copy Code
Dim instance As BitmapSourceViewer
C# 
[TemplatePartAttribute(Name="PART_Magnify", Type=System.Windows.Controls.Canvas)]
public class BitmapSourceViewer : ContentControl, IElement  
Managed Extensions for C++ 
[TemplatePartAttribute(Name="PART_Magnify", Type=System.Windows.Controls.Canvas)]
public __gc class BitmapSourceViewer : public ContentControl, IElement  
C++/CLI 
[TemplatePartAttribute(Name="PART_Magnify", Type=System.Windows.Controls.Canvas)]
public ref class BitmapSourceViewer : public ContentControl, IElement  
XAML Object Element Usage 

<BitmapSourceViewer .../>

Example

This example will create an instance of the BitmapSourceViewer control and add it to a form.

Visual BasicCopy Code
Public Sub BitmapSourceViewer_BitmapSourceViewer()
   Dim runner As CrossThreadTestRunner = New CrossThreadTestRunner()

   runner.RunInSTA(AddressOf BitmapSourceViewer_BitmapSourceViewerProc)
End Sub

Private Class MyWindow1 : Inherits Window
   Private theViewer As BitmapSourceViewer

   Public Sub New()
      ' Create the viewer
      theViewer = New BitmapSourceViewer()

      ' Create Dock Panel

      Dim panel As DockPanel = New DockPanel()
      Content = panel

      DockPanel.SetDock(theViewer, Dock.Bottom)

      theViewer.HorizontalAlignment = System.Windows.HorizontalAlignment.Center
      theViewer.VerticalAlignment = System.Windows.VerticalAlignment.Bottom
      theViewer.ImageHorizontalAlignment = System.Windows.HorizontalAlignment.Left
      theViewer.ImageVerticalAlignment = System.Windows.VerticalAlignment.Top
      theViewer.Frame = New Size(10, 5)
      theViewer.FrameBackground = Brushes.Red
      theViewer.FrameShadow = New Size(5, 5)
      theViewer.FrameShadowBackground = Brushes.Blue
      theViewer.UseDpi = True

      panel.Children.Add(theViewer)

      ' load an image into the viewer
      theViewer.Source = New BitmapImage(New Uri("C:\program files\LEAD Technologies\LEADTOOLS 15\Images\Image1.jpg"))

      Title = String.Format("Size mode = {0}, double click to change", theViewer.SizeMode)

      AddHandler theViewer.MouseDoubleClick, AddressOf theViewer_MouseDoubleClick
   End Sub

   Private Sub theViewer_MouseDoubleClick(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
      Select Case theViewer.SizeMode
         Case PaintSizeMode.Normal
            theViewer.SizeMode = PaintSizeMode.Stretch

         Case PaintSizeMode.Stretch
            theViewer.SizeMode = PaintSizeMode.Fit

         Case PaintSizeMode.Fit
            theViewer.SizeMode = PaintSizeMode.FitAlways

         Case PaintSizeMode.FitAlways
            theViewer.SizeMode = PaintSizeMode.FitWidth

         Case PaintSizeMode.FitWidth
            theViewer.SizeMode = PaintSizeMode.Normal
      End Select

      Title = String.Format("Size mode = {0}, double click to change", theViewer.SizeMode)

   End Sub
End Class
C#Copy Code
class MyWindow1 : Window 

   BitmapSourceViewer theViewer; 
   public MyWindow1() 
   { 
      // Create the  viewer 
      theViewer = new BitmapSourceViewer(); 
 
      // Create Dock Panel 
 
      DockPanel panel = new DockPanel(); 
      Content = panel; 
 
      DockPanel.SetDock(theViewer, Dock.Bottom); 
 
      theViewer.HorizontalAlignment= HorizontalAlignment.Center; 
      theViewer.VerticalAlignment= VerticalAlignment.Bottom; 
      theViewer.ImageHorizontalAlignment = HorizontalAlignment.Left; 
      theViewer.ImageVerticalAlignment = VerticalAlignment.Top; 
      theViewer.Frame = new Size(10, 5); 
      theViewer.FrameBackground = Brushes.Red; 
      theViewer.FrameShadow = new Size(5, 5); 
      theViewer.FrameShadowBackground = Brushes.Blue; 
      theViewer.UseDpi = true; 
 
      panel.Children.Add(theViewer); 
 
      // load an image into the viewer 
      theViewer.Source = new BitmapImage(new Uri(@"C:\program files\LEAD Technologies\LEADTOOLS 15\Images\slave.jpg")); 
 
      Title = string.Format("Size mode = {0}, double click to change", theViewer.SizeMode); 
 
      theViewer.MouseDoubleClick += new MouseButtonEventHandler(theViewer_MouseDoubleClick); 
   } 
 
   void theViewer_MouseDoubleClick(object sender, MouseButtonEventArgs e) 
   { 
      switch(theViewer.SizeMode) 
      { 
         case PaintSizeMode.Normal: 
            theViewer.SizeMode = PaintSizeMode.Stretch; 
            break; 
 
         case PaintSizeMode.Stretch: 
            theViewer.SizeMode = PaintSizeMode.Fit; 
            break; 
 
         case PaintSizeMode.Fit: 
            theViewer.SizeMode = PaintSizeMode.FitAlways; 
            break; 
 
         case PaintSizeMode.FitAlways: 
            theViewer.SizeMode = PaintSizeMode.FitWidth; 
            break; 
 
         case PaintSizeMode.FitWidth: 
            theViewer.SizeMode = PaintSizeMode.Normal; 
            break; 
      } 
 
      Title = string.Format("Size mode = {0}, double click to change", theViewer.SizeMode); 
 
   } 
}
XAMLCopy Code
<Window x:Class="WPFSamples.BitmapSourceViewer" Height="600" Width="800" 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"> 
  <DockPanel> 
    <Leadtools_Windows_Controls:BitmapSourceViewer Name="theViewer" Source="file:///C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\slave.jpg" DockPanel.Dock="Bottom" HorizontalAlignment="Center" VerticalAlignment="Bottom" Frame="10,5" FrameBackground="Red" FrameShadow="5,5" FrameShadowBackground="Blue" UseDpi="False" MouseDoubleClick="theViewer_MouseDoubleClick" /> 
  </DockPanel> 
  <Window.Title> 
              "Size mode =Normal, double click to change" 
          </Window.Title> 
</Window>

Remarks

The BitmapSourceViewer is used to display graphics from a bitmap, metafile, icon, JPEG, GIF or PNG (or any other image file format supported by LEADTOOLS for WPF) file.
Set the Source property to a BitmapSource or to a DrawingImage object to be displayed.
The BitmapSourceViewer control can automatically handle zooming and scrolling.

Inheritance Hierarchy

System.Object
   System.Windows.Threading.DispatcherObject
      System.Windows.DependencyObject
         System.Windows.Media.Visual
            System.Windows.UIElement
               System.Windows.FrameworkElement
                  System.Windows.Controls.Control
                     System.Windows.Controls.ContentControl
                        Leadtools.Windows.Controls.BitmapSourceViewer

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Vista, and Windows Server 2003 family

See Also