CreateGdPictureImageFromHBitmap(IntPtr) Method
In This Topic
Creates a new GdPicture image from an instantiated HBitmap object based on Microsoft® Windows® Graphics Device Interface (GDI),
provided as an IntPtr value. The newly created image 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 Overloads Function CreateGdPictureImageFromHBitmap( _
ByVal As IntPtr _
) As Integer
public int CreateGdPictureImageFromHBitmap(
IntPtr
)
public function CreateGdPictureImageFromHBitmap(
: IntPtr
): Integer;
public function CreateGdPictureImageFromHBitmap(
: IntPtr
) : int;
public: int CreateGdPictureImageFromHBitmap(
IntPtr
)
public:
int CreateGdPictureImageFromHBitmap(
IntPtr
)
Parameters
- hBitmap
- A pointer to a HBitmap object based on Microsoft® Windows® Graphics Device Interface (GDI), as an IntPtr value.
This pointer 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 GdPicture image 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.
Example
Creating a GdPicture image from GDI bitmap and saving to a PNG file.
using (GdPictureImaging gdpictureImaging = new GdPictureImaging())
using (Bitmap bmpScreenCapture = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height))
using (Graphics graphics = Graphics.FromImage(bmpScreenCapture))
{
graphics.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, bmpScreenCapture.Size, CopyPixelOperation.SourceCopy);
int imageID = gdpictureImaging.CreateGdPictureImageFromHBitmap(bmpScreenCapture.GetHbitmap());
gdpictureImaging.SaveAsPNG(imageID, "image.png");
gdpictureImaging.ReleaseGdPictureImage(imageID);
}
Example
Creating a GdPicture image from GDI bitmap and saving to a PNG file.
using (GdPictureImaging gdpictureImaging = new GdPictureImaging())
using (Bitmap bmpScreenCapture = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height))
using (Graphics graphics = Graphics.FromImage(bmpScreenCapture))
{
graphics.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, bmpScreenCapture.Size, CopyPixelOperation.SourceCopy);
int imageID = gdpictureImaging.CreateGdPictureImageFromHBitmap(bmpScreenCapture.GetHbitmap());
gdpictureImaging.SaveAsPNG(imageID, "image.png");
gdpictureImaging.ReleaseGdPictureImage(imageID);
}
See Also