GdPicture.NET.14
GdPicture14 Namespace / GdPictureImaging Class / CreateGdPictureImageFromDIB Method / CreateGdPictureImageFromDIB(IntPtr) Method
A pointer to a Microsoft® Windows® Graphics Device Independent Bitmap (DIB) handle, 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.
Example





In This Topic
CreateGdPictureImageFromDIB(IntPtr) Method
In This Topic
Creates a new GdPicture image from an instantiated Device Independent Bitmap (DIB) handle provided as IntrPtr. 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 CreateGdPictureImageFromDIB( _
   ByVal Dib As IntPtr _
) As Integer
public int CreateGdPictureImageFromDIB( 
   IntPtr Dib
)
public function CreateGdPictureImageFromDIB( 
    Dib: IntPtr
): Integer; 
public function CreateGdPictureImageFromDIB( 
   Dib : IntPtr
) : int;
public: int CreateGdPictureImageFromDIB( 
   IntPtr Dib
) 
public:
int CreateGdPictureImageFromDIB( 
   IntPtr Dib
) 

Parameters

Dib
A pointer to a Microsoft® Windows® Graphics Device Independent Bitmap (DIB) handle, 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.

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

Please note, that created GdPicture image will use its own pixel allocation.

This method requires the Image Documents component to run.

Example
Creating a GdPicture image from a dib and saving to a PNG file.
using (GdPictureImaging gdpictureImaging = new GdPictureImaging())
using (Stream stream = File.Open("image.bmp", FileMode.Open))
{
    // Load a dib from a bitmap file the sake of demonstration.
    // A dib is a bmp without its header.
    const int bmpHeaderSize = 14;
    int dibSize = (int)stream.Seek(0, SeekOrigin.End) - bmpHeaderSize;
    byte[] buffer = new byte[dibSize];
    stream.Seek(bmpHeaderSize, SeekOrigin.Begin);
    stream.Read(buffer, 0, dibSize);
 
    // Create a dib with the content of the buffer.
    IntPtr dibPointer = MemoryUtils.Malloc(dibSize);
    Marshal.Copy(buffer, 0, dibPointer, dibSize);
 
    // Create the GdPicture image and save it as a PNG.
    int imageID = gdpictureImaging.CreateGdPictureImageFromDIB(dibPointer);
    gdpictureImaging.SaveAsPNG(imageID, "image.png");
    gdpictureImaging.ReleaseGdPictureImage(imageID);
    MemoryUtils.Free(dibPointer);
}
See Also