CreateGdPictureImageFromRawBits Method (GdPictureImaging)
Creates a new GdPicture image from raw bitmap in memory.
public int CreateGdPictureImageFromRawBits(
int ,
int ,
int ,
PixelFormat ,
IntPtr
)
public function CreateGdPictureImageFromRawBits(
: Integer;
: Integer;
: Integer;
: PixelFormat;
: IntPtr
): Integer;
public function CreateGdPictureImageFromRawBits(
: int,
: int,
: int,
: PixelFormat,
: IntPtr
) : int;
public: int CreateGdPictureImageFromRawBits(
int ,
int ,
int ,
PixelFormat ,
IntPtr
)
public:
int CreateGdPictureImageFromRawBits(
int ,
int ,
int ,
PixelFormat ,
IntPtr
)
'Declaration
Public Function CreateGdPictureImageFromRawBits( _
ByVal As Integer, _
ByVal As Integer, _
ByVal As Integer, _
ByVal As PixelFormat, _
ByVal As IntPtr _
) As Integer
Parameters
- Width
- Specifies the width, in pixels, of the bitmap.
- Height
- Specifies the height, in pixels, of the bitmap.
- Stride
- Specifies the byte offset between the beginning of one scan line and the
next. This is usually (but not necessarily) the number of bytes in the
pixel format (for example, 2 for 16 bit per pixel) multiplied by the
width of the bitmap. The value passed to this parameter must be a multiple
of four.
- PixelFormat
- Specifies the pixel format of the bitmap. A member of the PixelFormat
enumeration.
- Bits
- Pointer to an array of bytes that contains the pixel data. The caller is
responsible for allocating and freeing the block of memory pointed to by
this parameter.
Return Value
0: The image could not be created. Use the GetStat() method to determine the reason this method
failed.
Non-zero: GdPicture image identifier. The created image. The ReleaseGdPictureImage() method must be subsequently used to release the image from the memory.
Creating a GdPicture image from raw bits and saving to a PNG file.
using (GdPictureImaging gdpictureImaging = new GdPictureImaging())
{
// Create a buffer to store 8x8 pixels and change the color of a diagonal.
byte[] bytes = new byte[64];
int index = 0;
while (index < 64)
{
bytes[index] = 0xff;
index += 9;
}
// Copy the managed buffer to and unmanaged buffer.
IntPtr unmanagedPointer = MemoryUtils.Malloc(bytes.Length);
Marshal.Copy(bytes, 0, unmanagedPointer, bytes.Length);
int imageID = gdpictureImaging.CreateGdPictureImageFromRawBits(8, 8, 8, System.Drawing.Imaging.PixelFormat.Format8bppIndexed, unmanagedPointer);
gdpictureImaging.SaveAsPNG(imageID, "image.png");
gdpictureImaging.ReleaseGdPictureImage(imageID);
MemoryUtils.Free(unmanagedPointer);
}