GdPicture.NET Reference Guide
CreateGdPictureImageFromBitmap Method
Example 





GdPicture14 Namespace > GdPictureImaging Class : CreateGdPictureImageFromBitmap Method
A System.Drawing.Bitmap object that contains the image data to load. This object must be initialized with the proper image data and it must be disposed of by the user as well.
Creates a new GdPictureImage object from an image data stored in a System.Drawing.Bitmap object. The newly created image object is identified by its unique non-zero image identifier.

Please note that it is your responsibility to release the image resources once you have no use for them.

Syntax
'Declaration
 
Public Function CreateGdPictureImageFromBitmap( _
   ByVal Bm As Bitmap _
) As Integer
public int CreateGdPictureImageFromBitmap( 
   Bitmap Bm
)
public function CreateGdPictureImageFromBitmap( 
    Bm: Bitmap
): Integer; 
public function CreateGdPictureImageFromBitmap( 
   Bm : Bitmap
) : int;
public: int CreateGdPictureImageFromBitmap( 
   Bitmap* Bm
) 
public:
int CreateGdPictureImageFromBitmap( 
   Bitmap^ Bm
) 

Parameters

Bm
A System.Drawing.Bitmap object that contains the image data to load. This object must be initialized with the proper image data and it must be disposed of by the user as well.

Return Value

A unique image identifier of the GdPictureImage object representing the newly created image. The returned value is non-zero if the image is successfully created. Please first of all use the GetStat method to determine if this method has been successful.

Be aware that you need to release the image with the ReleaseGdPictureImage method after being used.

Remarks
We strongly recommend using the GetStat method to identify the specific reason for the method's failure.
Example
How to create your image from the previously defined Bitmap object.
Dim caption As String = "Example: CreateGdPictureImageFromBitmap"
Using oImage As GdPictureImaging = New GdPictureImaging()
    Dim bm As System.Drawing.Bitmap = New System.Drawing.Bitmap("image.bmp")
    'Creating a GdPicture Image object from a bitmap.
    Dim imageID As Integer = oImage.CreateGdPictureImageFromBitmap(bm)
    If oImage.GetStat() = GdPictureStatus.OK Then
        'Processing the created image.
        If oImage.IsPixelFormatHasAlpha(imageID) Then
            If oImage.SaveAsPBM(imageID, "image.pbm") = GdPictureStatus.OK Then
                MessageBox.Show("The image has been saved successfully.", caption)
            Else
                MessageBox.Show("The image can't be saved. Status: " + oImage.GetStat().ToString(), caption)
            End If
        End If
        'Releasing the image resource after it has been used.
        oImage.ReleaseGdPictureImage(imageID)
    Else
        MessageBox.Show("The image can't be created. Status: " + oImage.GetStat().ToString(), caption)
    End If
    bm.Dispose()
End Using
string caption = "Example: CreateGdPictureImageFromBitmap";
using (GdPictureImaging oImage = new GdPictureImaging())
{
    System.Drawing.Bitmap bm = new System.Drawing.Bitmap("image.bmp");
    //Creating a GdPicture Image object from a bitmap.
    int imageID = oImage.CreateGdPictureImageFromBitmap(bm);
    if (oImage.GetStat() == GdPictureStatus.OK)
    {
        //Processing the created image.
        if (oImage.IsPixelFormatHasAlpha(imageID))
        {
            if (oImage.SaveAsPBM(imageID, "image.pbm") == GdPictureStatus.OK)
                MessageBox.Show("The image has been saved successfully.", caption);
            else
                MessageBox.Show("The image can't be saved. Status: " + oImage.GetStat().ToString(), caption);
        }
        //Releasing the image resource after it has been used.
        oImage.ReleaseGdPictureImage(imageID);
    }
    else
        MessageBox.Show("The image can't be created. Status: " + oImage.GetStat().ToString(), caption);
    bm.Dispose();
}
See Also

Reference

GdPictureImaging Class
GdPictureImaging Members
GetStat Method
ReleaseGdPictureImage Method
IsPixelFormatHasAlpha Method
SaveAsPBM Method
CreateGdPictureImageFromFile(String) Method