GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / AddImageFromBitmap Method / AddImageFromBitmap(Bitmap,Boolean,Boolean) Method
A Bitmap object specifying an image resource to be added into the current document.
Applicable only for 1 bit per pixel images. Indicates, whether the inserted image shall be treated as an image mask (or stencil mask). The recommended default value is false.
Set this parameter to true if you want to draw an image directly, otherwise set it to false.

If positive, then the new page is added into the current document and the image is drawn on its whole surface.

Example





In This Topic
AddImageFromBitmap(Bitmap,Boolean,Boolean) Method
In This Topic
Adds an image resource stored in a Bitmap object to the currently loaded PDF document according to what you have specified. You can either draw the image directly using this method or you can draw it later using the returned image resource name. The dimensions of the newly added page are the same as the original dimensions of the inserted image.
Syntax
'Declaration
 
Public Overloads Function AddImageFromBitmap( _
   ByVal bitmap As Bitmap, _
   ByVal ImageMask As Boolean, _
   ByVal DrawImage As Boolean _
) As String
public string AddImageFromBitmap( 
   Bitmap bitmap,
   bool ImageMask,
   bool DrawImage
)
public function AddImageFromBitmap( 
    bitmap: Bitmap;
    ImageMask: Boolean;
    DrawImage: Boolean
): String; 
public function AddImageFromBitmap( 
   bitmap : Bitmap,
   ImageMask : boolean,
   DrawImage : boolean
) : String;
public: string* AddImageFromBitmap( 
   Bitmap* bitmap,
   bool ImageMask,
   bool DrawImage
) 
public:
String^ AddImageFromBitmap( 
   Bitmap^ bitmap,
   bool ImageMask,
   bool DrawImage
) 

Parameters

bitmap
A Bitmap object specifying an image resource to be added into the current document.
ImageMask
Applicable only for 1 bit per pixel images. Indicates, whether the inserted image shall be treated as an image mask (or stencil mask). The recommended default value is false.
DrawImage
Set this parameter to true if you want to draw an image directly, otherwise set it to false.

If positive, then the new page is added into the current document and the image is drawn on its whole surface.

Return Value

Returns a name of the newly inserted image resource strictly bounded to the currently loaded PDF document. The GetStat method can be subsequently used to determine if this method has been successful.

This name can be subsequently used with the DrawImage method to draw an image onto the page.

Remarks
This method is only allowed for use with non-encrypted documents.

It is recommend to use the GetStat method to identify the specific reason for the method's failure, if any.

Example
How to draw an image within a PDF document using a bitmap.
Dim caption As String = "Example: AddImageFromBitmap"
Dim gdpictureImaging As New GdPictureImaging()
Dim imageID As Integer = gdpictureImaging.CreateGdPictureImageFromFile("image1.tif")
If gdpictureImaging.GetStat() = GdPictureStatus.OK Then
    Dim bitmap As Bitmap = gdpictureImaging.GetBitmapFromGdPictureImage(imageID)
    If gdpictureImaging.GetStat() = GdPictureStatus.OK Then
        Dim gdpicturePDF As New GdPicturePDF()
        If gdpicturePDF.NewPDF() = GdPictureStatus.OK Then
            Dim imageResName As String = gdpicturePDF.AddImageFromBitmap(bitmap, False, True)
            If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                If gdpicturePDF.SaveToFile("test_AddImageFromBitmap.pdf", True) = GdPictureStatus.OK Then
                    MessageBox.Show("The example has been followed successfully and the file has been saved.", caption)
                Else
                    MessageBox.Show("The file can't be saved. Status: " + gdpicturePDF.GetStat().ToString(), caption)
                End If
            Else
                MessageBox.Show("The AddImageFromBitmap() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
            End If
        Else
            MessageBox.Show("The NewPDF() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
        End If
        gdpicturePDF.Dispose()
    Else
        MessageBox.Show("The GetBitmapFromGdPictureImage() method has failed with the status: " + gdpictureImaging.GetStat().ToString(), caption)
    End If
    gdpictureImaging.ReleaseGdPictureImage(imageID)
Else
    MessageBox.Show("The CreateGdPictureImageFromFile() method has failed with the status: " + gdpictureImaging.GetStat().ToString(), caption)
End If
gdpictureImaging.Dispose()
string caption = "Example: AddImageFromBitmap";
GdPictureImaging gdpictureImaging = new GdPictureImaging();
int imageID = gdpictureImaging.CreateGdPictureImageFromFile("image.tif");
if (gdpictureImaging.GetStat() == GdPictureStatus.OK)
{
    Bitmap bitmap = gdpictureImaging.GetBitmapFromGdPictureImage(imageID);
    if (gdpictureImaging.GetStat() == GdPictureStatus.OK)
    {
        GdPicturePDF gdpicturePDF = new GdPicturePDF();
        if (gdpicturePDF.NewPDF() == GdPictureStatus.OK)
        {
            string imageResName = gdpicturePDF.AddImageFromBitmap(bitmap, false, true);
            if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
            {
                    if (gdpicturePDF.SaveToFile("test_AddImageFromBitmap.pdf", true) == GdPictureStatus.OK)
                        MessageBox.Show("The example has been followed successfully and the file has been saved.", caption);
                    else
                        MessageBox.Show("The file can't be saved. Status: " + gdpicturePDF.GetStat().ToString(), caption);
            }
            else
                MessageBox.Show("The AddImageFromBitmap() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
        }
        else
            MessageBox.Show("The NewPDF() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
        gdpicturePDF.Dispose();
    }
    else
        MessageBox.Show("The GetBitmapFromGdPictureImage() method has failed with the status: " + gdpictureImaging.GetStat().ToString(), caption);
    gdpictureImaging.ReleaseGdPictureImage(imageID);
}
else
    MessageBox.Show("The CreateGdPictureImageFromFile() method has failed with the status: " + gdpictureImaging.GetStat().ToString(), caption);
gdpictureImaging.Dispose();
See Also