←Select platform

Image Property

Summary

The image associated with this RasterImageListItem object.

Syntax

C#
VB
C++
public RasterImage Image { get; set; } 
  
Public Property Image As Leadtools.RasterImage 
public: 
property Leadtools.RasterImage^ Image { 
   Leadtools.RasterImage^ get(); 
   void set (    Leadtools.RasterImage^ ); 
} 

Property Value

An Leadtools.RasterImage object associated with this RasterImageListItem object. The default value is null (Nothing in VB).

Remarks

The Page property specifies the 1-based page number to view from this image.

The value of RasterImage.Page is not used to control the page number of the item to be viewed in this item. Instead, use the Page property. This allows the same Leadtools.RasterImage object to be used multiple items while setting the Page property to different values.

The RasterImageList control will paint this image onto the item surface. If the item does not have an image, the value of this property is null (Nothing in VB) and, nothing is painted.

The RasterImageList control paints the image in the following manner:

  • If the image size is less than or equal to the ItemImageSize value, the image is painted with its original size only centered onto the item surface.
  • If the image size is grater than the ItemImageSize value, the image is stretched to this smaller size and the aspect ratio is kept the same.
  • It is recommended that you populate the items with "thumbnail" images. This will increase the performance of the item painting operation. In such cases, use the Tag or FileName properties to store the information needed to load the image in its original size when requested.

The value of RasterImage.Page is not used to control the page number of the item to be viewed in this item. Instead, use the Page property. This allows the same Leadtools.RasterImage object to be used in multiple items while setting the Page property to different values.

Example

C#
VB
using Leadtools.WinForms; 
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
 
class MyForm2 : Form 
{ 
   RasterImageViewer viewer; 
   RasterImageList imageList; 
   RasterCodecs codecs; 
 
   public MyForm2() 
   { 
      // Set the size of the form 
      Size = new Size(400, 200); 
 
      // Create a new RasterImageList control 
      imageList = new RasterImageList(); 
      imageList.Dock = DockStyle.Left; 
      imageList.SelectionMode = RasterImageListSelectionMode.Single; 
      Controls.Add(imageList); 
      imageList.BringToFront(); 
 
      // Add a handler to the SelectedIndexChanged event 
      imageList.SelectedIndexChanged += new EventHandler(rasterImageList_SelectedIndexChanged); 
 
      Splitter splitter = new Splitter(); 
      splitter.Dock = DockStyle.Left; 
      Controls.Add(splitter); 
      splitter.BringToFront(); 
 
      viewer = new RasterImageViewer(); 
      viewer.Dock = DockStyle.Fill; 
      Controls.Add(viewer); 
      viewer.BringToFront(); 
 
      // Now load all our images 
      codecs = new RasterCodecs(); 
 
      string folderName = LEAD_VARS.ImagesDir; 
      string[] files = Directory.GetFiles(folderName, "*.*"); 
 
      // This is going to be a lengthy operation 
      // Suspend painting the RasterImageList 
      imageList.BeginUpdate(); 
 
      foreach (string fileName in files) 
      { 
         // Load the image as a thumbnail 
         RasterImage image = LoadThumbnail(fileName); 
 
         // Only add an item if we loaded the image successfuly 
         if (image != null) 
         { 
            // Create an item 
            RasterImageListItem item = new RasterImageListItem(); 
 
 
            // Setup the item information 
            item.Image = image; 
            item.Text = Path.GetFileName(fileName); 
            item.Page = 1; 
 
            // To load this image in original size later 
            item.FileName = fileName; 
 
            // Add the item into RasterImageList 
            imageList.Items.Add(item); 
         } 
      } 
 
      imageList.EndUpdate(); 
 
   } 
 
   private void rasterImageList_SelectedIndexChanged(object sender, EventArgs e) 
   { 
      // User has selected an item from the RasterImageList control. 
      // Re-load the item image and show it in original size in the viewer 
 
      // Get the selected item(s) 
      RasterImageListItemCollection selectedItems = imageList.SelectedItems; 
      if (selectedItems != null && selectedItems.Count == 1) 
      { 
         RasterImageListItem item = selectedItems[0]; 
 
         // Load the image in its original size and set it in the viewer 
         viewer.Image = codecs.Load( 
            item.FileName, 
            0, 
            CodecsLoadByteOrder.BgrOrGray, 
            1, 
            1); 
      } 
   } 
 
   private RasterImage LoadThumbnail(string fileName) 
   { 
      RasterImage image = null; 
 
      try 
      { 
         // See if we can load this image 
         CodecsImageInfo info = codecs.GetInformation(fileName, false, 1); 
 
         if (info.Format != RasterImageFormat.Unknown) 
         { 
            // Yes, calculate the thumbnail size to fit into RasterImageList.ItemImageSize 
            Rectangle rc = new Rectangle( 
               0, 
               0, 
               imageList.ItemImageSize.Width, 
               imageList.ItemImageSize.Height); 
 
            rc = RasterImageList.GetFixedAspectRatioImageRectangle(info.Width, info.Height, rc); 
 
            // Load the thumbnail 
            image = codecs.Load( 
               fileName, 
               rc.Width, 
               rc.Height, 
               24, 
               RasterSizeFlags.Resample, 
               CodecsLoadByteOrder.BgrOrGray, 
               1, 
               1); 
         } 
         else 
            image = null; 
      } 
      catch 
      { 
         image = null; 
      } 
      return image; 
   } 
} 
 
public void RasterImageList_Image() 
{ 
   MyForm2 form = new MyForm2(); 
   form.ShowDialog(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; 
} 
Imports Leadtools.WinForms 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Drawing 
 
Private Class MyForm2 : Inherits Form 
   Private viewer As RasterImageViewer 
   Private imageList As RasterImageList 
   Private codecs As RasterCodecs 
 
   Public Sub New() 
      ' Set the size of the form 
      Size = New Size(400, 200) 
 
      ' Create a new RasterImageList control 
      imageList = New RasterImageList() 
      imageList.Dock = DockStyle.Left 
      imageList.SelectionMode = RasterImageListSelectionMode.Single 
      Controls.Add(imageList) 
      imageList.BringToFront() 
 
      ' Add a handler to the SelectedIndexChanged event 
      AddHandler imageList.SelectedIndexChanged, AddressOf rasterImageList_SelectedIndexChanged 
 
      Dim splitter As Splitter = New Splitter() 
      splitter.Dock = DockStyle.Left 
      Controls.Add(splitter) 
      splitter.BringToFront() 
 
      viewer = New RasterImageViewer() 
      viewer.Dock = DockStyle.Fill 
      Controls.Add(viewer) 
      viewer.BringToFront() 
 
      ' Now load all our images 
      codecs = New RasterCodecs() 
 
      Dim folderName As String = LEAD_VARS.ImagesDir 
      Dim files As String() = Directory.GetFiles(folderName, "*.*") 
 
      ' This is going to be a lengthy operation 
      ' Suspend painting the RasterImageList 
      imageList.BeginUpdate() 
 
      For Each fileName As String In files 
         ' Load the image as a thumbnail 
         Dim image As RasterImage = LoadThumbnail(fileName) 
 
         ' Only add an item if we loaded the image successfuly 
         If Not image Is Nothing Then 
            ' Create an item 
            Dim item As RasterImageListItem = New RasterImageListItem() 
 
 
            ' Setup the item information 
            item.Image = image 
            item.Text = Path.GetFileName(fileName) 
            item.Page = 1 
 
            ' To load this image in original size later 
            item.FileName = fileName 
 
            ' Add the item into RasterImageList 
            imageList.Items.Add(item) 
         End If 
      Next fileName 
 
      imageList.EndUpdate() 
 
   End Sub 
 
   Private Sub rasterImageList_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) 
      ' User has selected an item from the RasterImageList control. 
      ' Re-load the item image and show it in original size in the viewer 
 
      ' Get the selected item(s) 
      Dim selectedItems As RasterImageListItemCollection = imageList.SelectedItems 
      If Not selectedItems Is Nothing AndAlso selectedItems.Count = 1 Then 
         Dim item As RasterImageListItem = selectedItems(0) 
 
         ' Load the image in its original size and set it in the viewer 
         viewer.Image = codecs.Load(item.FileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1) 
      End If 
   End Sub 
 
   Private Function LoadThumbnail(ByVal fileName As String) As RasterImage 
      Dim image As RasterImage = Nothing 
 
      Try 
         ' See if we can load this image 
         Dim info As CodecsImageInfo = codecs.GetInformation(fileName, False, 1) 
 
         If info.Format <> RasterImageFormat.Unknown Then 
            ' Yes, calculate the thumbnail size to fit into RasterImageList.ItemImageSize 
            Dim rc As Rectangle = New Rectangle(0, 0, imageList.ItemImageSize.Width, imageList.ItemImageSize.Height) 
 
            rc = RasterImageList.GetFixedAspectRatioImageRectangle(info.Width, info.Height, rc) 
 
            ' Load the thumbnail 
            image = codecs.Load(fileName, rc.Width, rc.Height, 24, RasterSizeFlags.Resample, CodecsLoadByteOrder.BgrOrGray, 1, 1) 
         Else 
            image = Nothing 
         End If 
      Catch 
         image = Nothing 
      End Try 
      Return image 
   End Function 
End Class 
 
Public Sub RasterImageList_Image() 
   Dim form As MyForm2 = New MyForm2() 
   form.ShowDialog() 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
End Class 

Requirements

Target Platforms

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.WinForms Assembly