Leadtools.Windows.Controls Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.03.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
   Implements IElement 
Visual Basic (Usage)Copy Code
Dim instance As BitmapSourceViewerElement
C# 
public class BitmapSourceViewerElement : FrameworkElement, IElement  
Managed Extensions for C++ 
public __gc class BitmapSourceViewerElement : public FrameworkElement, IElement  
C++/CLI 
public ref class BitmapSourceViewerElement : public FrameworkElement, IElement  
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 CrossThreadTestRunner = New 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("C:\program files\LEAD Technologies\LEADTOOLS 15\Images\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(@"C:\program files\LEAD Technologies\LEADTOOLS 15\Images\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 or to a DrawingImage objects 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, and Windows Server 2003 family

See Also