GdPicture.NET.14.API
GdPicture14 Namespace / GdPictureImaging Class / CreateGdPictureImageFromRawBits Method
Specifies the width, in pixels, of the bitmap.
Specifies the height, in pixels, of the bitmap.
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.
Specifies the pixel format of the bitmap. A member of the PixelFormat enumeration.
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.
Example





In This Topic
CreateGdPictureImageFromRawBits Method (GdPictureImaging)
In This Topic
Creates a new GdPicture image from raw bitmap in memory.
Syntax
'Declaration
 
Public Function CreateGdPictureImageFromRawBits( _
   ByVal Width As Integer, _
   ByVal Height As Integer, _
   ByVal Stride As Integer, _
   ByVal PixelFormat As GdPicturePixelFormat, _
   ByVal Bits As IntPtr _
) As Integer
public int CreateGdPictureImageFromRawBits( 
   int Width,
   int Height,
   int Stride,
   GdPicturePixelFormat PixelFormat,
   IntPtr Bits
)
public function CreateGdPictureImageFromRawBits( 
    Width: Integer;
    Height: Integer;
    Stride: Integer;
    PixelFormat: GdPicturePixelFormat;
    Bits: IntPtr
): Integer; 
public function CreateGdPictureImageFromRawBits( 
   Width : int,
   Height : int,
   Stride : int,
   PixelFormat : GdPicturePixelFormat,
   Bits : IntPtr
) : int;
public: int CreateGdPictureImageFromRawBits( 
   int Width,
   int Height,
   int Stride,
   GdPicturePixelFormat PixelFormat,
   IntPtr Bits
) 
public:
int CreateGdPictureImageFromRawBits( 
   int Width,
   int Height,
   int Stride,
   GdPicturePixelFormat PixelFormat,
   IntPtr Bits
) 

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.
Remarks
Warning: Do not remove the raw bitmap from the memory until you delete the created GdPicture image.

This method requires the Image Documents component to run.

Example
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);
}
See Also