Leadtools.Windows.Controls Send comments on this topic. | Back to Introduction - LEADTOOLS WPF | Help Version 16.5.9.25
BitmapSourceViewerElement Class
See Also  Members   Example 
Leadtools.Windows.Controls Namespace : BitmapSourceViewerElement Class





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

Syntax

Visual Basic (Declaration) 
Public Class BitmapSourceViewerElement 
   Inherits FrameworkElement
Visual Basic (Usage)Copy Code
Dim instance As BitmapSourceViewerElement
C# 
public class BitmapSourceViewerElement : FrameworkElement 
C++/CLI 
public ref class BitmapSourceViewerElement : public FrameworkElement 
XAML Object Element Usage 

<BitmapSourceViewerElement .../>

XAML Object Element Usage 

<BitmapSourceViewerElement .../>

Example

For XAML example, refer to Source.

This example will create an instance of the BitmapSourceViewerElement control and add it to a window.

Visual BasicCopy Code
Public Sub BitmapSourceViewerElement_BitmapSourceViewerElementProc()
   ' Refer to MyWindow1 class defined in ImagePanViewer.Viewer example.
   Dim window As MyWindow1 = New MyWindow1()
   window.ShowDialog()
End Sub

Public Sub BitmapSourceViewerElement_BitmapSourceViewerElement()
   Dim runner As Leadtools.Help.CrossThreadTestRunner = New Leadtools.Help.CrossThreadTestRunner()

   runner.RunInSTA(AddressOf BitmapSourceViewerElement_BitmapSourceViewerElementProc)
End Sub

Private Class MyWindow1 : Inherits Window
   Private theImage As BitmapSourceViewerElement

   Public Sub New()
      ' Create the viewer
      theImage = New BitmapSourceViewerElement()

      ' Create Dock Panel

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

      DockPanel.SetDock(theImage, Dock.Bottom)

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

      panel.Children.Add(theImage)

      ' load an image into the viewer
          theImage.Source = New BitmapImage(New Uri(LeadtoolsExamples.Common.ImagesPath.Path + "Image1.jpg"))

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

      AddHandler theImage.MouseDown, AddressOf theImage_MouseClick
   End Sub

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

         Case PaintSizeMode.Stretch
            theImage.SizeMode = PaintSizeMode.Fit

         Case PaintSizeMode.Fit
            theImage.SizeMode = PaintSizeMode.FitAlways

         Case PaintSizeMode.FitAlways
            theImage.SizeMode = PaintSizeMode.FitWidth

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

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

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

   BitmapSourceViewerElement theImage; 
   public MyWindow1() 
   { 
      // Create the  viewer 
      theImage = new BitmapSourceViewerElement(); 
 
      // Create Dock Panel 
 
      DockPanel panel = new DockPanel(); 
      Content = panel; 
 
      DockPanel.SetDock(theImage, Dock.Bottom); 
 
      theImage.HorizontalAlignment = HorizontalAlignment.Center; 
      theImage.VerticalAlignment= VerticalAlignment.Bottom; 
      theImage.Frame = new Size(10, 5); 
      theImage.FrameBackground = Brushes.Red; 
      theImage.FrameShadow = new Size(5, 5); 
      theImage.FrameShadowBackground = Brushes.Blue; 
      theImage.UseDpi = true; 
 
      panel.Children.Add(theImage); 
 
      // load an image into the viewer 
      theImage.Source = new BitmapImage(new Uri(LeadtoolsExamples.Common.ImagesPath.Path + "slave.jpg")); 
 
      Title = string.Format("Size mode = {0}, click to change", theImage.SizeMode); 
 
      theImage.MouseDown += new MouseButtonEventHandler(theImage_MouseClick); 
   } 
 
   void theImage_MouseClick(object sender, MouseButtonEventArgs e) 
   { 
      switch(theImage.SizeMode) 
      { 
         case PaintSizeMode.Normal: 
            theImage.SizeMode = PaintSizeMode.Stretch; 
            break; 
 
         case PaintSizeMode.Stretch: 
            theImage.SizeMode = PaintSizeMode.Fit; 
            break; 
 
         case PaintSizeMode.Fit: 
            theImage.SizeMode = PaintSizeMode.FitAlways; 
            break; 
 
         case PaintSizeMode.FitAlways: 
            theImage.SizeMode = PaintSizeMode.FitWidth; 
            break; 
 
         case PaintSizeMode.FitWidth: 
            theImage.SizeMode = PaintSizeMode.Normal; 
            break; 
      } 
 
      Title = string.Format("Size mode = {0}, double click to change", theImage.SizeMode); 
 
   } 
}

Remarks

The BitmapSourceViewerElement 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 object to be displayed.
The BitmapSourceViewerElement control can automatically handle zooming.

Inheritance Hierarchy

System.Object
   System.Windows.Threading.DispatcherObject
      System.Windows.DependencyObject
         System.Windows.Media.Visual
            System.Windows.UIElement
               System.Windows.FrameworkElement
                  Leadtools.Windows.Controls.BitmapSourceViewerElement

Requirements

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

See Also