←Select platform

AutoDisposeImage Property

Summary

Indicates whether to auto dispose the old image when a new image is set into this RasterPictureBox.

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

Property Value

true if the image in Image is automatically disposed when a new image is set; otherwise, false. Default value is true.

Remarks

By default, whenever you set a new image into the Image property, the old image (if any) is disposed. Set the value of this property to false to prevent disposing of the old image.

Example
C#
using Leadtools; 
using Leadtools.Controls; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
 
 
public void RasterPictureBox_AutoDisposeImage() 
{ 
   RasterPictureBox viewer = new RasterPictureBox(); 
   // Load two image2 
   RasterCodecs codecs = new RasterCodecs(); 
   string file1 = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"); 
   string file2 = Path.Combine(LEAD_VARS.ImagesDir, "Image2.cmp"); 
 
 
   RasterImage image1 = codecs.Load(file1); 
   RasterImage image2 = codecs.Load(file2); 
 
   // Make sure the AutoDisposeImage property of the viewer is set to true 
   viewer.AutoDisposeImage = true; 
 
   // Set the first image into the viewer 
   viewer.Image = image1; 
 
   // Now set the second image into the viewer (this disposes the first image since the AutoDisposeImage property is true) 
   viewer.Image = image2; 
 
   // Try to access the first image, it generates a NullReferenceException exception since the image has been disposed 
   Debug.WriteLine("Try to access the first image, it generates a NullReferenceException exception since the image has been disposed."); 
   try 
   { 
      int width = image1.Width; 
      Debug.WriteLine(string.Format("Width is {0} pixels", width)); 
   } 
   catch (NullReferenceException ex) 
   { 
      Debug.WriteLine(ex.Message); 
   } 
 
   // Set the image to null (will dispose the second image as well) 
   viewer.Image = null; 
 
   // Now re-load the two images 
   image1 = codecs.Load(file1); 
   image2 = codecs.Load(file2); 
 
   // Make sure the AutoDisposeImage property of the viewer is set to false 
   viewer.AutoDisposeImage = false; 
 
   // Set the first image into the viewer 
   viewer.Image = image1; 
 
   // Now set the second image into the viewer (this will not disposes the first image since the AutoDisposeImage property is false) 
   viewer.Image = image2; 
 
   // Try to access the first image, it should work fine this time 
   try 
   { 
      int width = image1.Width; 
      Debug.WriteLine(string.Format("Width is {0} pixels", width)); 
   } 
   catch (NullReferenceException ex) 
   { 
      Debug.WriteLine(ex.Message); 
   } 
 
   // Set the image to null (will not dispose the second image) 
   viewer.Image = null; 
 
   // We should now dispose the two images manually 
   image1.Dispose(); 
   image2.Dispose(); 
   codecs.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

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

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