GdPicture.NET.14.API
GdPicture14 Namespace / GdPictureDocumentUtilities Class / DisposeImage Method
The unique image identifier of the image resource to be released.
Example





In This Topic
DisposeImage Method (GdPictureDocumentUtilities)
In This Topic
Releases a specified image and its corresponding image resource from memory. This method is particularly useful if you work with images outside the GdPictureImaging class, for example if you are using the GdPicturePDF class.
Syntax
'Declaration
 
Public Shared Function DisposeImage( _
   ByVal ImageID As Integer _
) As GdPictureStatus
public static GdPictureStatus DisposeImage( 
   int ImageID
)
public function DisposeImage( 
    ImageID: Integer
): GdPictureStatus; static; 
public static function DisposeImage( 
   ImageID : int
) : GdPictureStatus;
public: static GdPictureStatus DisposeImage( 
   int ImageID
) 
public:
static GdPictureStatus DisposeImage( 
   int ImageID
) 

Parameters

ImageID
The unique image identifier of the image resource to be released.

Return Value

A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK.
Remarks
It is always a best practice to release images you have created once you have no use for them. You can find some our recommendations in this Best Practices tutorial.
Example
How to dispose of the used image.
Dim gdpicturePDF As GdPicturePDF = New GdPicturePDF()
If gdpicturePDF.LoadFromFile("test.pdf", False) = GdPictureStatus.OK Then
    Dim pageCount As Integer = gdpicturePDF.GetPageCount()
    Dim status As GdPictureStatus = gdpicturePDF.GetStat()
    If (status = GdPictureStatus.OK) AndAlso (pageCount > 0) Then
        Dim imageCount As Integer = gdpicturePDF.GetPageImageCount()
        status = gdpicturePDF.GetStat()
        If (status = GdPictureStatus.OK) AndAlso (imageCount > 0) Then
            Dim imageID As Integer = 0
            For i As Integer = 1 To imageCount
                imageID = gdpicturePDF.ExtractPageImage(i)
                status = gdpicturePDF.GetStat()
                If status = GdPictureStatus.OK Then
                    'Do your stuff with the extracted image here.
                    ' ...
                    'Dispose of the image after you have used it.
                    If GdPictureDocumentUtilities.DisposeImage(imageID) <> GdPictureStatus.OK Then
                        MessageBox.Show("The disposal of the image has failed. Status: " + status.ToString(), "GdPicture")
                    End If
                End If
            Next
        Else
            If status = GdPictureStatus.OK Then
                MessageBox.Show("The first page doesn't contain any image.", "GdPicture")
            Else
                MessageBox.Show("Error: " + status.ToString(), "GdPicture")
            End If
        End If
    Else
        If status = GdPictureStatus.OK Then
            MessageBox.Show("This file doesn't contain any page.", "GdPicture")
        Else
            MessageBox.Show("Error: " + status.ToString(), "GdPicture")
        End If
    End If
Else
    MessageBox.Show("The file can't be loaded.", "GdPicture")
End If
gdpicturePDF.Dispose()
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if (gdpicturePDF.LoadFromFile("test.pdf", false) == GdPictureStatus.OK)
{
    int pageCount = gdpicturePDF.GetPageCount();
    GdPictureStatus status = gdpicturePDF.GetStat();
    if ((status == GdPictureStatus.OK) && (pageCount > 0))
    {
        int imageCount = gdpicturePDF.GetPageImageCount();
        status = gdpicturePDF.GetStat();
        if ((status == GdPictureStatus.OK) && (imageCount > 0))
        {
            int imageID = 0;
            for (int i = 1; i <= imageCount; i++)
            {
                imageID = gdpicturePDF.ExtractPageImage(i);
                status = gdpicturePDF.GetStat();
                if (status == GdPictureStatus.OK)
                {
                    //Do your stuff with the extracted image here.
                    //...
                    //Dispose of the image after you have used it.
                    if (GdPictureDocumentUtilities.DisposeImage(imageID) != GdPictureStatus.OK)
                        MessageBox.Show("The disposal of the image has failed. Status: " + status.ToString(), "GdPicture");
                }
            }
        }
        else
        {
            if (status == GdPictureStatus.OK)
                MessageBox.Show("The first page doesn't contain any image.", "GdPicture");
            else
                MessageBox.Show("Error: " + status.ToString(), "GdPicture");
        }
    }
    else
    {
        if (status == GdPictureStatus.OK)
            MessageBox.Show("This file doesn't contain any page.", "GdPicture");
        else
            MessageBox.Show("Error: " + status.ToString(), "GdPicture");
    }
}
else
    MessageBox.Show("The file can't be loaded.", "GdPicture");
gdpicturePDF.Dispose();
See Also