←Select platform

AutoDisposeImages Property

Summary

Indicates whether to automatically dispose item images, SVG documents and floaters.

Syntax
C#
C++/CLI
public virtual bool AutoDisposeImages { get; set; } 
public:  
   virtual property bool AutoDisposeImages 
   { 
      bool get() 
      void set(bool value) 
   } 

Property Value

true to automatically dispose item images, SVG documents and floaters; otherwise, false. Default value is true.

Remarks

When the value of the AutoDisposeImages is set to true, the image viewer will automatically call the RasterImage.Dispose method on an item's Image, SvgDocument and Floater when the item is removed from the Items collection or when the control itself is disposed.

The control will check if an image is used with multiple items (for example, if multiple items are using the same image but to show different pages). In this case, the control will correctly dispose the image only once.

If you setup the items with images that you do not want to dispose of and are going to re-use somewhere else, you need to set the value of the AutoDisposeImages property to false.

You can also temporarily change the value of the AutoDisposeImages property if you want to save the item image before you dispose it. For example, set the AutoDisposeImages property to false, call "Removed" on the Items collection to remove the item, then re-set the AutoDisposeImages property back to true.

Note that if you set the AutoDisposeImages value to false and you do not dispose the item images yourself, the .NET garbage collector will eventually detect that these images are not used anymore and will dispose them for you when the control and any other reference to these images are no longer used in your application. This is not recommended since the image data contains unmanaged memory and resources that are not returned to the system even though the owner object is no longer used.

For more information, refer to Image Viewer Items.

Example

This example will show the effect of AutoDisposeImages.

C#
using Leadtools; 
using Leadtools.Controls; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
 
 
public ImageViewerForm _form = new ImageViewerForm(); 
public ImageViewer _imageViewer; 
public RasterImage image1, image2; 
 
public void ImageViewerAutoDisposeImagesExample() 
{ 
   // Get the ImageViewer control from the form 
   _imageViewer = _form.ImageViewer; 
 
   // Load 2 images 
            
   using (RasterCodecs codecs = new RasterCodecs()) 
   { 
      image1 = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "image1.cmp")); 
      image2 = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "image2.cmp")); 
   } 
 
   // Enable AutoDisposeImages 
   _imageViewer.AutoDisposeImages = true; 
 
   // Set the first image into the viewer  
   _imageViewer.Image = image1; 
 
   // Set the second image into the viewer 
   // This disposes the first image since the AutoDisposeImages property is true  
   _imageViewer.Image = image2; 
 
   if (image1.IsDisposed) 
      Debug.WriteLine("Image1 has been disposed"); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Controls Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.