Gets or sets a value indicating whether to auto dispose the old image when a new image is set into this RasterImageBox.
public bool AutoDisposeImages { get; set; } Public Property AutoDisposeImages As Boolean
true if the Leadtools.RasterImage object in Image is automatically disposed when a new image is set; otherwise, false. Default value is true.
By default, whenever you set a new Leadtools.RasterImage object 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.
using Leadtools.Help;using Leadtools.Windows.Controls;using Leadtools.ImageProcessing;using Leadtools.Codecs;public void RasterImageBox_AutoDisposeImages(RasterImageBox imageBox){// Load two image2RasterCodecs 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 image box is set to trueimageBox.AutoDisposeImages = true;// Set the first image into the image boximageBox.Image = image1;// Now set the second image into the image box (this disposes the first image since the AutoDisposeImage property is true)imageBox.Image = image2;// Try to access the first image, it generates a NullReferenceException exception since the image has been disposedMessageBox.Show("Try to access the first image, it generates a NullReferenceException exception since the image has been disposed.");try{int width = image1.Width;MessageBox.Show(string.Format("Width is {0} pixels", width));}catch (NullReferenceException ex){MessageBox.Show(ex.Message);}// Set the image to null (will dispose the second image as well)imageBox.Image = null;// Now re-load the two imagesimage1 = codecs.Load(file1);image2 = codecs.Load(file2);// Make sure the AutoDisposeImage property of the image box is set to falseimageBox.AutoDisposeImages = false;// Set the first image into the image boximageBox.Image = image1;// Now set the second image into the image box (this will not disposes the first image since the AutoDisposeImage property is false)imageBox.Image = image2;// Try to access the first image, it should work fine this timetry{int width = image1.Width;MessageBox.Show(string.Format("Width is {0} pixels", width));}catch (NullReferenceException ex){MessageBox.Show(ex.Message);}// Set the image to null (will not dispose the second image)imageBox.Image = null;// We should now dispose the two images manuallyimage1.Dispose();image2.Dispose();codecs.Dispose();}static class LEAD_VARS{public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";}
Imports Leadtools.Windows.ControlsImports Leadtools.ImageProcessingImports Leadtools.CodecsImports LeadtoolsPublic Sub RasterImageBox_AutoDisposeImages(ByVal imageBox As RasterImageBox)' Load two image2Dim codecs As New RasterCodecs()Dim file1 As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")Dim file2 As String = Path.Combine(LEAD_VARS.ImagesDir, "Image2.cmp")Dim image1 As RasterImage = codecs.Load(file1)Dim image2 As RasterImage = codecs.Load(file2)' Make sure the AutoDisposeImage property of the image box is set to trueimageBox.AutoDisposeImages = True' Set the first image into the image boximageBox.Image = image1' Now set the second image into the image box (this disposes the first image since the AutoDisposeImage property is true)imageBox.Image = image2' Try to access the first image, it generates a NullReferenceException exception since the image has been disposedMessageBox.Show("Try to access the first image, it generates a NullReferenceException exception since the image has been disposed.")TryDim width As Integer = image1.WidthMessageBox.Show(String.Format("Width is {0} pixels", width))Catch ex As NullReferenceExceptionMessageBox.Show(ex.Message)End Try' Set the image to Nothing (will dispose the second image as well)imageBox.Image = Nothing' Now re-load the two imagesimage1 = codecs.Load(file1)image2 = codecs.Load(file2)' Make sure the AutoDisposeImage property of the image box is set to falseimageBox.AutoDisposeImages = False' Set the first image into the image boximageBox.Image = image1' Now set the second image into the image box (this will not disposes the first image since the AutoDisposeImage property is false)imageBox.Image = image2' Try to access the first image, it should work fine this timeTryDim width As Integer = image1.WidthMessageBox.Show(String.Format("Width is {0} pixels", width))Catch ex As NullReferenceExceptionMessageBox.Show(ex.Message)End Try' Set the image to Nothing (will not dispose the second image)imageBox.Image = Nothing' We should now dispose the two images manuallyimage1.Dispose()image2.Dispose()codecs.Dispose()End SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
