using System; using System.Runtime.InteropServices; namespace Vanara.PInvoke { public static partial class Gdi32 { /// Flags for CreateDIBitmap. [PInvokeData("wingdi.h", MSDNShortId = "e9a5b525-a6b6-4309-9e53-69d274b85783")] [Flags] public enum CBM { /// /// If this flag is set, the system uses the data pointed to by the lpbInit and lpbmi parameters to initialize the bitmap bits. /// CBM_INIT = 4 } /// Specifies the type of color values in DIB functions. [PInvokeData("Wingdi.h", MSDNShortId = "dd183494")] public enum DIBColorMode : int { /// The BITMAPINFO structure contains an array of literal RGB values. DIB_RGB_COLORS = 0, /// /// The bmiColors member of the BITMAPINFO structure is an array of 16-bit indexes into the logical palette of the device context /// specified by hdc. /// DIB_PAL_COLORS = 1 } /// The type of fill operation to be performed. [PInvokeData("wingdi.h", MSDNShortId = "b996d47d-5aaf-4b13-8643-209744e5a04b")] public enum FloodFillType : uint { /// /// The fill area is bounded by the color specified by the crColor parameter. This style is identical to the filling performed by /// the FloodFill function. /// FLOODFILLBORDER, /// /// The fill area is defined by the color that is specified by crColor. Filling continues outward in all directions as long as /// the color is encountered. This style is useful for filling areas with multicolored boundaries. /// FLOODFILLSURFACE } /// Flags for . [PInvokeData("wingdi.h", MSDNShortId = "c88c1137-5690-4139-9d10-90d036e8f31c")] public enum GradientFillMode : uint { /// /// In this mode, two endpoints describe a rectangle. The rectangle is defined to have a constant color (specified by the /// TRIVERTEX structure) for the left and right edges. GDI interpolates the color from the left to right edge and fills the interior. /// GRADIENT_FILL_RECT_H = 0x00000000, /// /// In this mode, two endpoints describe a rectangle. The rectangle is defined to have a constant color (specified by the /// TRIVERTEX structure) for the top and bottom edges. GDI interpolates the color from the top to bottom edge and fills the interior. /// GRADIENT_FILL_RECT_V = 0x00000001, /// /// In this mode, an array of TRIVERTEX structures is passed to GDI along with a list of array indexes that describe separate /// triangles. GDI performs linear interpolation between triangle vertices and fills the interior. Drawing is done directly in /// 24- and 32-bpp modes. Dithering is performed in 16-, 8-, 4-, and 1-bpp mode. /// GRADIENT_FILL_TRIANGLE = 0x00000002, /// Undocumented. GRADIENT_FILL_OP_FLAG = 0x000000ff, } /// /// Defines how the color data for the source rectangle is to be combined with the color data for the destination rectangle to /// achieve the final color when using the function. /// [PInvokeData("Wingdi.h", MSDNShortId = "dd183370")] public enum RasterOperationMode { /// Copies the source rectangle directly to the destination rectangle. SRCCOPY = 0x00CC0020, /// Combines the colors of the source and destination rectangles by using the Boolean OR operator. SRCPAINT = 0x00EE0086, /// Combines the colors of the source and destination rectangles by using the Boolean AND operator. SRCAND = 0x008800C6, /// Combines the colors of the source and destination rectangles by using the Boolean XOR operator. SRCINVERT = 0x00660046, /// /// Combines the inverted colors of the destination rectangle with the colors of the source rectangle by using the Boolean AND operator. /// SRCERASE = 0x00440328, /// NOTSRCCOPY = 0x00330008, /// Copies the inverted source rectangle to the destination. NOTSRCERASE = 0x001100A6, /// /// Merges the colors of the source rectangle with the brush currently selected in hdcDest, by using the Boolean AND operator. /// MERGECOPY = 0x00C000CA, /// /// Merges the colors of the inverted source rectangle with the colors of the destination rectangle by using the Boolean OR operator. /// MERGEPAINT = 0x00BB0226, /// Copies the brush currently selected in hdcDest, into the destination bitmap. PATCOPY = 0x00F00021, /// /// Combines the colors of the brush currently selected in hdcDest, with the colors of the inverted source rectangle by using the /// Boolean OR operator. The result of this operation is combined with the colors of the destination rectangle by using the /// Boolean OR operator. /// PATPAINT = 0x00FB0A09, /// /// Combines the colors of the brush currently selected in hdcDest, with the colors of the destination rectangle by using the /// Boolean XOR operator. /// PATINVERT = 0x005A0049, /// Inverts the destination rectangle. DSTINVERT = 0x00550009, /// /// Fills the destination rectangle using the color associated with index 0 in the physical palette. (This color is black for the /// default physical palette.) /// BLACKNESS = 0x00000042, /// /// Fills the destination rectangle using the color associated with index 1 in the physical palette. (This color is white for the /// default physical palette.) /// WHITENESS = 0x00FF0062, /// Prevents the bitmap from being mirrored. NOMIRRORBITMAP = -2147483648, /// /// Includes any windows that are layered on top of your window in the resulting image.By default, the image only contains your /// window.Note that this generally cannot be used for printing device contexts. /// CAPTUREBLT = 0x40000000 } /// Stretching mode. [PInvokeData("wingdi.h", MSDNShortId = "a4408e28-d7ac-44e9-905d-efa75c60e503")] public enum StretchMode : uint { /// /// Performs a Boolean AND operation using the color values for the eliminated and existing pixels. If the bitmap is a monochrome /// bitmap, this mode preserves black pixels at the expense of white pixels. /// BLACKONWHITE = 1, /// /// Performs a Boolean OR operation using the color values for the eliminated and existing pixels. If the bitmap is a monochrome /// bitmap, this mode preserves white pixels at the expense of black pixels. /// WHITEONBLACK = 2, /// Deletes the pixels. This mode deletes all eliminated lines of pixels without trying to preserve their information. COLORONCOLOR = 3, /// /// Maps pixels from the source rectangle into blocks of pixels in the destination rectangle. The average color over the /// destination block of pixels approximates the color of the source pixels. /// HALFTONE = 4, /// Same as BLACKONWHITE. STRETCH_ANDSCANS = BLACKONWHITE, /// Same as WHITEONBLACK. STRETCH_ORSCANS = WHITEONBLACK, /// Same as COLORONCOLOR. STRETCH_DELETESCANS = COLORONCOLOR, /// Same as HALFTONE. STRETCH_HALFTONE = HALFTONE, } /// The AlphaBlend function displays bitmaps that have transparent or semitransparent pixels. /// A handle to the destination device context. /// The x-coordinate, in logical units, of the upper-left corner of the destination rectangle. /// The y-coordinate, in logical units, of the upper-left corner of the destination rectangle. /// The width, in logical units, of the destination rectangle. /// The height, in logical units, of the destination rectangle. /// A handle to the source device context. /// The x-coordinate, in logical units, of the upper-left corner of the source rectangle. /// The y-coordinate, in logical units, of the upper-left corner of the source rectangle. /// The width, in logical units, of the source rectangle. /// The height, in logical units, of the source rectangle. /// /// The alpha-blending function for source and destination bitmaps, a global alpha value to be applied to the entire source bitmap, /// and format information for the source bitmap. The source and destination blend functions are currently limited to AC_SRC_OVER. /// /// If the function succeeds, the return value is TRUE. If the function fails, the return value is FALSE. /// /// If the source rectangle and destination rectangle are not the same size, the source bitmap is stretched to match the destination /// rectangle. If the SetStretchBltMode function is used, the iStretchMode value is automatically converted to COLORONCOLOR for this /// function (that is, BLACKONWHITE, WHITEONBLACK, and HALFTONE are changed to COLORONCOLOR). /// /// The destination coordinates are transformed by using the transformation currently specified for the destination device context. /// The source coordinates are transformed by using the transformation currently specified for the source device context. /// /// An error occurs (and the function returns FALSE) if the source device context identifies an enhanced metafile device context. /// /// If destination and source bitmaps do not have the same color format, AlphaBlend converts the source bitmap to match the /// destination bitmap. /// /// /// AlphaBlend does not support mirroring. If either the width or height of the source or destination is negative, this call will fail. /// /// /// When rendering to a printer, first call GetDeviceCaps with SHADEBLENDCAPS to determine if the printer supports blending with /// AlphaBlend. Note that, for a display DC, all blending operations are supported and these flags represent whether the operations /// are accelerated. /// /// /// If the source and destination are the same surface that is, they are both the screen or the same memory bitmap and the source and /// destination rectangles overlap, an error occurs and the function returns FALSE. /// /// /// The source rectangle must lie completely within the source surface, otherwise an error occurs and the function returns FALSE. /// /// AlphaBlend fails if the width or height of the source or destination is negative. /// /// The SourceConstantAlpha member of BLENDFUNCTION specifies an alpha transparency value to be used on the entire source bitmap. The /// SourceConstantAlpha value is combined with any per-pixel alpha values. If SourceConstantAlpha is 0, it is assumed that the image /// is transparent. Set the SourceConstantAlpha value to 255 (which indicates that the image is opaque) when you only want to use /// per-pixel alpha values. /// /// [DllImport(Lib.Gdi32, SetLastError = true, EntryPoint = "GdiAlphaBlend")] [return: MarshalAs(UnmanagedType.Bool)] [PInvokeData("Wingdi.h", MSDNShortId = "dd183351")] public static extern bool AlphaBlend(HDC hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest, HDC hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc, BLENDFUNCTION blendFunction); /// /// The BitBlt function performs a bit-block transfer of the color data corresponding to a rectangle of pixels from the specified /// source device context into a destination device context. /// /// A handle to the destination device context. /// The x-coordinate, in logical units, of the upper-left corner of the destination rectangle. /// The y-coordinate, in logical units, of the upper-left corner of the destination rectangle. /// The width, in logical units, of the destination rectangle. /// The height, in logical units, of the destination rectangle. /// A handle to the source device context. /// The x-coordinate, in logical units, of the upper-left corner of the source rectangle. /// The y-coordinate, in logical units, of the upper-left corner of the source rectangle. /// /// A raster-operation code. These codes define how the color data for the source rectangle is to be combined with the color data for /// the destination rectangle to achieve the final color. /// /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// /// /// BitBlt only does clipping on the destination DC. /// /// If a rotation or shear transformation is in effect in the source device context, BitBlt returns an error. If other /// transformations exist in the source device context (and a matching transformation is not in effect in the destination device /// context), the rectangle in the destination device context is stretched, compressed, or rotated, as necessary. /// /// /// If the color formats of the source and destination device contexts do not match, the BitBlt function converts the source color /// format to match the destination format. /// /// /// When an enhanced metafile is being recorded, an error occurs if the source device context identifies an enhanced-metafile device context. /// /// /// Not all devices support the BitBlt function. For more information, see the RC_BITBLT raster capability entry in the GetDeviceCaps /// function as well as the following functions: MaskBlt, PlgBlt, and StretchBlt. /// /// /// BitBlt returns an error if the source and destination device contexts represent different devices. To transfer data between DCs /// for different devices, convert the memory bitmap to a DIB by calling GetDIBits. To display the DIB to the second device, call /// SetDIBits or StretchDIBits. /// /// ICM: No color management is performed when blits occur. /// [DllImport(Lib.Gdi32, ExactSpelling = true, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] [PInvokeData("Wingdi.h", MSDNShortId = "dd183370")] public static extern bool BitBlt(HDC hdc, int nXDest, int nYDest, int nWidth, int nHeight, HDC hdcSrc, int nXSrc, int nYSrc, RasterOperationMode dwRop); /// /// The CreateBitmap function creates a bitmap with the specified width, height, and color format (color planes and bits-per-pixel). /// /// The bitmap width, in pixels. /// The bitmap height, in pixels. /// The number of color planes used by the device. /// The number of bits required to identify the color of a single pixel. /// /// A pointer to an array of color data used to set the colors in a rectangle of pixels. Each scan line in the rectangle must be word /// aligned (scan lines that are not word aligned must be padded with zeros). If this parameter is NULL, the contents of the /// new bitmap is undefined. /// /// /// If the function succeeds, the return value is a handle to a bitmap. /// If the function fails, the return value is NULL. /// This function can return the following value. /// /// /// Return code /// Description /// /// /// ERROR_INVALID_BITMAP /// The calculated size of the bitmap is less than zero. /// /// /// /// /// The CreateBitmap function creates a device-dependent bitmap. /// /// After a bitmap is created, it can be selected into a device context by calling the SelectObject function. However, the bitmap can /// only be selected into a device context if the bitmap and the DC have the same format. /// /// /// The CreateBitmap function can be used to create color bitmaps. However, for performance reasons applications should use /// CreateBitmap to create monochrome bitmaps and CreateCompatibleBitmap to create color bitmaps. Whenever a color bitmap /// returned from CreateBitmap is selected into a device context, the system checks that the bitmap matches the format of the /// device context it is being selected into. Because CreateCompatibleBitmap takes a device context, it returns a bitmap that /// has the same format as the specified device context. Thus, subsequent calls to SelectObject are faster with a color bitmap from /// CreateCompatibleBitmap than with a color bitmap returned from CreateBitmap. /// /// /// If the bitmap is monochrome, zeros represent the foreground color and ones represent the background color for the destination /// device context. /// /// /// If an application sets the nWidth or nHeight parameters to zero, CreateBitmap returns the handle to a 1-by-1 pixel, /// monochrome bitmap. /// /// When you no longer need the bitmap, call the DeleteObject function to delete it. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createbitmap HBITMAP CreateBitmap( int nWidth, int nHeight, // UINT nPlanes, UINT nBitCount, const VOID *lpBits ); [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "b52e1baf-6a81-44bc-a061-4d42e6f4ed64")] public static extern SafeHBITMAP CreateBitmap(int nWidth, int nHeight, uint nPlanes, uint nBitCount, IntPtr lpBits); /// /// The CreateBitmap function creates a bitmap with the specified width, height, and color format (color planes and bits-per-pixel). /// /// The bitmap width, in pixels. /// The bitmap height, in pixels. /// The number of color planes used by the device. /// The number of bits required to identify the color of a single pixel. /// /// A pointer to an array of color data used to set the colors in a rectangle of pixels. Each scan line in the rectangle must be word /// aligned (scan lines that are not word aligned must be padded with zeros). If this parameter is NULL, the contents of the /// new bitmap is undefined. /// /// /// If the function succeeds, the return value is a handle to a bitmap. /// If the function fails, the return value is NULL. /// This function can return the following value. /// /// /// Return code /// Description /// /// /// ERROR_INVALID_BITMAP /// The calculated size of the bitmap is less than zero. /// /// /// /// /// The CreateBitmap function creates a device-dependent bitmap. /// /// After a bitmap is created, it can be selected into a device context by calling the SelectObject function. However, the bitmap can /// only be selected into a device context if the bitmap and the DC have the same format. /// /// /// The CreateBitmap function can be used to create color bitmaps. However, for performance reasons applications should use /// CreateBitmap to create monochrome bitmaps and CreateCompatibleBitmap to create color bitmaps. Whenever a color bitmap /// returned from CreateBitmap is selected into a device context, the system checks that the bitmap matches the format of the /// device context it is being selected into. Because CreateCompatibleBitmap takes a device context, it returns a bitmap that /// has the same format as the specified device context. Thus, subsequent calls to SelectObject are faster with a color bitmap from /// CreateCompatibleBitmap than with a color bitmap returned from CreateBitmap. /// /// /// If the bitmap is monochrome, zeros represent the foreground color and ones represent the background color for the destination /// device context. /// /// /// If an application sets the nWidth or nHeight parameters to zero, CreateBitmap returns the handle to a 1-by-1 pixel, /// monochrome bitmap. /// /// When you no longer need the bitmap, call the DeleteObject function to delete it. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createbitmap HBITMAP CreateBitmap( int nWidth, int nHeight, // UINT nPlanes, UINT nBitCount, const VOID *lpBits ); [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "b52e1baf-6a81-44bc-a061-4d42e6f4ed64")] public static extern SafeHBITMAP CreateBitmap(int nWidth, int nHeight, uint nPlanes, uint nBitCount, byte[] lpBits); /// /// The CreateBitmapIndirect function creates a bitmap with the specified width, height, and color format (color planes and bits-per-pixel). /// /// /// A pointer to a BITMAP structure that contains information about the bitmap. If an application sets the bmWidth or /// bmHeight members to zero, CreateBitmapIndirect returns the handle to a 1-by-1 pixel, monochrome bitmap. /// /// /// If the function succeeds, the return value is a handle to the bitmap. /// If the function fails, the return value is NULL. /// This function can return the following values. /// /// /// Return code /// Description /// /// /// ERROR_INVALID_PARAMETER /// One or more of the input parameters is invalid. /// /// /// ERROR_NOT_ENOUGH_MEMORY /// The bitmap is too big for memory to be allocated. /// /// /// /// /// The CreateBitmapIndirect function creates a device-dependent bitmap. /// /// After a bitmap is created, it can be selected into a device context by calling the SelectObject function. However, the bitmap can /// only be selected into a device context if the bitmap and the DC have the same format. /// /// /// While the CreateBitmapIndirect function can be used to create color bitmaps, for performance reasons applications should /// use CreateBitmapIndirect to create monochrome bitmaps and CreateCompatibleBitmap to create color bitmaps. Whenever a color /// bitmap from CreateBitmapIndirect is selected into a device context, the system must ensure that the bitmap matches the /// format of the device context it is being selected into. Because CreateCompatibleBitmap takes a device context, it returns /// a bitmap that has the same format as the specified device context. Thus, subsequent calls to SelectObject are faster with a color /// bitmap from CreateCompatibleBitmap than with a color bitmap returned from CreateBitmapIndirect. /// /// /// If the bitmap is monochrome, zeros represent the foreground color and ones represent the background color for the destination /// device context. /// /// When you no longer need the bitmap, call the DeleteObject function to delete it. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createbitmapindirect HBITMAP CreateBitmapIndirect( const // BITMAP *pbm ); [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "79f73e28-4ee3-472d-9a20-3ffe7cf2a6b5")] public static extern SafeHBITMAP CreateBitmapIndirect(in BITMAP pbm); /// /// The CreateCompatibleBitmap function creates a bitmap compatible with the device that is associated with the specified /// device context. /// /// A handle to a device context. /// The bitmap width, in pixels. /// The bitmap height, in pixels. /// /// If the function succeeds, the return value is a handle to the compatible bitmap (DDB). /// If the function fails, the return value is NULL. /// /// /// /// The color format of the bitmap created by the CreateCompatibleBitmap function matches the color format of the device /// identified by the hdc parameter. This bitmap can be selected into any memory device context that is compatible with the original device. /// /// /// Because memory device contexts allow both color and monochrome bitmaps, the format of the bitmap returned by the /// CreateCompatibleBitmap function differs when the specified device context is a memory device context. However, a /// compatible bitmap that was created for a nonmemory device context always possesses the same color format and uses the same color /// palette as the specified device context. /// /// /// Note: When a memory device context is created, it initially has a 1-by-1 monochrome bitmap selected into it. If this memory /// device context is used in CreateCompatibleBitmap, the bitmap that is created is a monochrome bitmap. To create a color /// bitmap, use the HDC that was used to create the memory device context, as shown in the following code: /// /// /// If an application sets the nWidth or nHeight parameters to zero, CreateCompatibleBitmap returns the handle to a 1-by-1 /// pixel, monochrome bitmap. /// /// /// If a DIB section, which is a bitmap created by the CreateDIBSection function, is selected into the device context identified by /// the hdc parameter, CreateCompatibleBitmap creates a DIB section. /// /// When you no longer need the bitmap, call the DeleteObject function to delete it. /// Examples /// For an example, see Scaling an Image. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createcompatiblebitmap HBITMAP CreateCompatibleBitmap( HDC // hdc, int cx, int cy ); [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "d2866beb-ff7a-4390-8651-e7bf458ddf88")] public static extern SafeHBITMAP CreateCompatibleBitmap(HDC hdc, int cx, int cy); /// /// The CreateDIBitmap function creates a compatible bitmap (DDB) from a DIB and, optionally, sets the bitmap bits. /// /// A handle to a device context. /// /// A pointer to a bitmap information header structure, BITMAPV5HEADER. /// /// If fdwInit is CBM_INIT, the function uses the bitmap information header structure to obtain the desired width and height of the /// bitmap as well as other information. Note that a positive value for the height indicates a bottom-up DIB while a negative value /// for the height indicates a top-down DIB. Calling CreateDIBitmap with fdwInit as CBM_INIT is equivalent to calling the /// CreateCompatibleBitmap function to create a DDB in the format of the device and then calling the SetDIBits function to translate /// the DIB bits to the DDB. /// /// /// /// Specifies how the system initializes the bitmap bits. The following value is defined. /// /// /// Value /// Meaning /// /// /// CBM_INIT /// /// If this flag is set, the system uses the data pointed to by the lpbInit and lpbmi parameters to initialize the bitmap bits. If /// this flag is clear, the data pointed to by those parameters is not used. /// /// /// /// If fdwInit is zero, the system does not initialize the bitmap bits. /// /// /// A pointer to an array of bytes containing the initial bitmap data. The format of the data depends on the biBitCount member /// of the BITMAPINFO structure to which the lpbmi parameter points. /// /// /// A pointer to a BITMAPINFO structure that describes the dimensions and color format of the array pointed to by the lpbInit parameter. /// /// /// /// Specifies whether the bmiColors member of the BITMAPINFO structure was initialized and, if so, whether bmiColors /// contains explicit red, green, blue (RGB) values or palette indexes. The fuUsage parameter must be one of the following values. /// /// /// /// Value /// Meaning /// /// /// DIB_PAL_COLORS /// /// A color table is provided and consists of an array of 16-bit indexes into the logical palette of the device context into which /// the bitmap is to be selected. /// /// /// /// DIB_RGB_COLORS /// A color table is provided and contains literal RGB values. /// /// /// /// /// If the function succeeds, the return value is a handle to the compatible bitmap. /// If the function fails, the return value is NULL. /// /// /// /// The DDB that is created will be whatever bit depth your reference DC is. To create a bitmap that is of different bit depth, use CreateDIBSection. /// /// /// For a device to reach optimal bitmap-drawing speed, specify fdwInit as CBM_INIT. Then, use the same color depth DIB as the video /// mode. When the video is running 4- or 8-bpp, use DIB_PAL_COLORS. /// /// The CBM_CREATDIB flag for the fdwInit parameter is no longer supported. /// When you no longer need the bitmap, call the DeleteObject function to delete it. /// /// ICM: No color management is performed. The contents of the resulting bitmap are not color matched after the bitmap has /// been created. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createdibitmap HBITMAP CreateDIBitmap( HDC hdc, const // BITMAPINFOHEADER *pbmih, DWORD flInit, const VOID *pjBits, const BITMAPINFO *pbmi, UINT iUsage ); [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "e9a5b525-a6b6-4309-9e53-69d274b85783")] public static extern SafeHBITMAP CreateDIBitmap(HDC hdc, ref BITMAPINFOHEADER pbmih, CBM flInit, byte[] pjBits, in BITMAPINFO pbmi, DIBColorMode iUsage); /// /// The CreateDIBSection function creates a DIB that applications can write to directly. The function gives you a pointer to /// the location of the bitmap bit values. You can supply a handle to a file-mapping object that the function will use to create the /// bitmap, or you can let the system allocate the memory for the bitmap. /// /// /// A handle to a device context. If the value of iUsage is DIB_PAL_COLORS, the function uses this device context's logical palette /// to initialize the DIB colors. /// /// /// A pointer to a BITMAPINFO structure that specifies various attributes of the DIB, including the bitmap dimensions and colors. /// /// /// /// The type of data contained in the bmiColors array member of the BITMAPINFO structure pointed to by pbmi (either logical /// palette indexes or literal RGB values). The following values are defined. /// /// /// /// Value /// Meaning /// /// /// DIB_PAL_COLORS /// The bmiColors member is an array of 16-bit indexes into the logical palette of the device context specified by hdc. /// /// /// DIB_RGB_COLORS /// The BITMAPINFO structure contains an array of literal RGB values. /// /// /// /// A pointer to a variable that receives a pointer to the location of the DIB bit values. /// /// A handle to a file-mapping object that the function will use to create the DIB. This parameter can be NULL. /// /// If hSection is not NULL, it must be a handle to a file-mapping object created by calling the CreateFileMapping function /// with the PAGE_READWRITE or PAGE_WRITECOPY flag. Read-only DIB sections are not supported. Handles created by other means will /// cause CreateDIBSection to fail. /// /// /// If hSection is not NULL, the CreateDIBSection function locates the bitmap bit values at offset dwOffset in the /// file-mapping object referred to by hSection. An application can later retrieve the hSection handle by calling the GetObject /// function with the HBITMAP returned by CreateDIBSection. /// /// /// If hSection is NULL, the system allocates memory for the DIB. In this case, the CreateDIBSection function ignores /// the dwOffset parameter. An application cannot later obtain a handle to this memory. The dshSection member of the /// DIBSECTION structure filled in by calling the GetObject function will be NULL. /// /// /// /// The offset from the beginning of the file-mapping object referenced by hSection where storage for the bitmap bit values is to /// begin. This value is ignored if hSection is NULL. The bitmap bit values are aligned on doubleword boundaries, so dwOffset /// must be a multiple of the size of a DWORD. /// /// /// /// If the function succeeds, the return value is a handle to the newly created DIB, and *ppvBits points to the bitmap bit values. /// /// If the function fails, the return value is NULL, and *ppvBits is NULL. /// This function can return the following value. /// /// /// Return code /// Description /// /// /// ERROR_INVALID_PARAMETER /// One or more of the input parameters is invalid. /// /// /// /// /// /// As noted above, if hSection is NULL, the system allocates memory for the DIB. The system closes the handle to that memory /// when you later delete the DIB by calling the DeleteObject function. If hSection is not NULL, you must close the hSection /// memory handle yourself after calling DeleteObject to delete the bitmap. /// /// You cannot paste a DIB section from one application into another application. /// /// CreateDIBSection does not use the BITMAPINFOHEADER parameters biXPelsPerMeter or biYPelsPerMeter and will not provide /// resolution information in the BITMAPINFO structure. /// /// /// You need to guarantee that the GDI subsystem has completed any drawing to a bitmap created by CreateDIBSection before you /// draw to the bitmap yourself. Access to the bitmap must be synchronized. Do this by calling the GdiFlush function. This applies to /// any use of the pointer to the bitmap bit values, including passing the pointer in calls to functions such as SetDIBits. /// /// ICM: No color management is done. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createdibsection HBITMAP CreateDIBSection( HDC hdc, const // BITMAPINFO *pbmi, UINT usage, VOID **ppvBits, HANDLE hSection, DWORD offset ); [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "9276ec84-2860-42be-a9f8-d4efb8d25eec")] public static extern SafeHBITMAP CreateDIBSection(HDC hdc, ref BITMAPINFO pbmi, DIBColorMode usage, out IntPtr ppvBits, HSECTION hSection, uint offset); /// /// /// The CreateDiscardableBitmap function creates a discardable bitmap that is compatible with the specified device. The bitmap /// has the same bits-per-pixel format and the same color palette as the device. An application can select this bitmap as the current /// bitmap for a memory device that is compatible with the specified device. /// /// /// Note This function is provided only for compatibility with 16-bit versions of Windows. Applications should use the /// CreateCompatibleBitmap function. /// /// /// A handle to a device context. /// The width, in pixels, of the bitmap. /// The height, in pixels, of the bitmap. /// /// If the function succeeds, the return value is a handle to the compatible bitmap (DDB). /// If the function fails, the return value is NULL. /// /// When you no longer need the bitmap, call the DeleteObject function to delete it. // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-creatediscardablebitmap HBITMAP CreateDiscardableBitmap( HDC // hdc, int cx, int cy ); [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "79168baf-26ea-4d24-b75c-d0658a56892c")] public static extern SafeHBITMAP CreateDiscardableBitmap(HDC hdc, int cx, int cy); /// The ExtFloodFill function fills an area of the display surface with the current brush. /// A handle to a device context. /// The x-coordinate, in logical units, of the point where filling is to start. /// The y-coordinate, in logical units, of the point where filling is to start. /// /// The color of the boundary or of the area to be filled. The interpretation of crColor depends on the value of the fuFillType /// parameter. To create a COLORREF color value, use the RGB macro. /// /// /// The type of fill operation to be performed. This parameter must be one of the following values. /// /// /// Value /// Meaning /// /// /// FLOODFILLBORDER /// /// The fill area is bounded by the color specified by the crColor parameter. This style is identical to the filling performed by the /// FloodFill function. /// /// /// /// FLOODFILLSURFACE /// /// The fill area is defined by the color that is specified by crColor. Filling continues outward in all directions as long as the /// color is encountered. This style is useful for filling areas with multicolored boundaries. /// /// /// /// /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. /// /// /// The following are some of the reasons this function might fail: /// /// /// The filling could not be completed. /// /// /// The specified point has the boundary color specified by the crColor parameter (if FLOODFILLBORDER was requested). /// /// /// The specified point does not have the color specified by crColor (if FLOODFILLSURFACE was requested). /// /// /// The point is outside the clipping regionthat is, it is not visible on the device. /// /// /// /// If the fuFillType parameter is FLOODFILLBORDER, the system assumes that the area to be filled is completely bounded by the color /// specified by the crColor parameter. The function begins filling at the point specified by the nXStart and nYStart parameters and /// continues in all directions until it reaches the boundary. /// /// /// If fuFillType is FLOODFILLSURFACE, the system assumes that the area to be filled is a single color. The function begins to fill /// the area at the point specified by nXStart and nYStart and continues in all directions, filling all adjacent regions containing /// the color specified by crColor. /// /// /// Only memory device contexts and devices that support raster-display operations support the ExtFloodFill function. To /// determine whether a device supports this technology, use the GetDeviceCaps function. /// /// Examples /// For an example, see "Adding Lines and Graphs to a Menu" in Using Menus. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-extfloodfill BOOL ExtFloodFill( HDC hdc, int x, int y, // COLORREF color, UINT type ); [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "b996d47d-5aaf-4b13-8643-209744e5a04b")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool ExtFloodFill(HDC hdc, int x, int y, COLORREF color, FloodFillType type); /// /// /// The FloodFill function fills an area of the display surface with the current brush. The area is assumed to be bounded as /// specified by the crFill parameter. /// /// /// Note The FloodFill function is included only for compatibility with 16-bit versions of Windows. Applications should /// use the ExtFloodFill function with FLOODFILLBORDER specified. /// /// /// A handle to a device context. /// The x-coordinate, in logical units, of the point where filling is to start. /// The y-coordinate, in logical units, of the point where filling is to start. /// The color of the boundary or the area to be filled. To create a COLORREF color value, use the RGB macro. /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. /// /// /// The following are reasons this function might fail: /// /// /// The fill could not be completed. /// /// /// The given point has the boundary color specified by the crFill parameter. /// /// /// The given point lies outside the current clipping regionthat is, it is not visible on the device. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-floodfill // BOOL FloodFill( HDC hdc, int x, int y, COLORREF color ); [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "e53bebb5-4e46-4ea4-8d41-c12f4c6645ef")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool FloodFill(HDC hdc, int x, int y, COLORREF color); /// /// The GetBitmapBits function copies the bitmap bits of a specified device-dependent bitmap into a buffer. /// /// Note This function is provided only for compatibility with 16-bit versions of Windows. Applications should use the /// GetDIBits function. /// /// /// A handle to the device-dependent bitmap. /// The number of bytes to copy from the bitmap into the buffer. /// A pointer to a buffer to receive the bitmap bits. The bits are stored as an array of byte values. /// /// If the function succeeds, the return value is the number of bytes copied to the buffer. /// If the function fails, the return value is zero. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getbitmapbits LONG GetBitmapBits( HBITMAP hbit, LONG cb, // LPVOID lpvBits ); [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "72e8cc6b-d282-451e-b6ec-0473d2daea7c")] public static extern int GetBitmapBits(HBITMAP hbit, int cb, byte[] lpvBits); /// /// The GetBitmapDimensionEx function retrieves the dimensions of a compatible bitmap. The retrieved dimensions must have been /// set by the SetBitmapDimensionEx function. /// /// A handle to a compatible bitmap (DDB). /// A pointer to a SIZE structure to receive the bitmap dimensions. For more information, see Remarks. /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. /// /// /// The function returns a data structure that contains fields for the height and width of the bitmap, in .01-mm units. If those /// dimensions have not yet been set, the structure that is returned will have zeros in those fields. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getbitmapdimensionex BOOL GetBitmapDimensionEx( HBITMAP hbit, // LPSIZE lpsize ); [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "3e4f5afc-26d3-4fb2-8d00-183165fdf471")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetBitmapDimensionEx(HBITMAP hbit, out SIZE lpsize); /// /// The GetDIBColorTable function retrieves RGB (red, green, blue) color values from a range of entries in the color table of /// the DIB section bitmap that is currently selected into a specified device context. /// /// A handle to a device context. A DIB section bitmap must be selected into this device context. /// A zero-based color table index that specifies the first color table entry to retrieve. /// The number of color table entries to retrieve. /// /// A pointer to a buffer that receives an array of RGBQUAD data structures containing color information from the DIB color table. /// The buffer must be large enough to contain as many RGBQUAD data structures as the value of cEntries. /// /// /// If the function succeeds, the return value is the number of color table entries that the function retrieves. /// If the function fails, the return value is zero. /// /// /// The GetDIBColorTable function should be called to retrieve the color table for DIB section bitmaps that use 1, 4, or 8 /// bpp. The biBitCount member of a bitmap associated BITMAPINFOHEADER structure specifies the number of bits-per-pixel. DIB /// section bitmaps with a biBitCount value greater than eight do not have a color table, but they do have associated color /// masks. Call the GetObject function to retrieve those color masks. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getdibcolortable UINT GetDIBColorTable( HDC hdc, UINT iStart, // UINT cEntries, RGBQUAD *prgbq ); [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "3e3319be-8a3d-4ac2-ba36-9dbf18243472")] public static extern uint GetDIBColorTable(HDC hdc, uint iStart, uint cEntries, [In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] RGBQUAD[] prgbq); /// /// The GetDIBits function retrieves the bits of the specified compatible bitmap and copies them into a buffer as a DIB using /// the specified format. /// /// A handle to the device context. /// A handle to the bitmap. This must be a compatible bitmap (DDB). /// The first scan line to retrieve. /// The number of scan lines to retrieve. /// /// A pointer to a buffer to receive the bitmap data. If this parameter is NULL, the function passes the dimensions and format /// of the bitmap to the BITMAPINFO structure pointed to by the lpbi parameter. /// /// A pointer to a BITMAPINFO structure that specifies the desired format for the DIB data. /// /// The format of the bmiColors member of the BITMAPINFO structure. It must be one of the following values. /// /// /// Value /// Meaning /// /// /// DIB_PAL_COLORS /// The color table should consist of an array of 16-bit indexes into the current logical palette. /// /// /// DIB_RGB_COLORS /// The color table should consist of literal red, green, blue (RGB) values. /// /// /// /// /// /// If the lpvBits parameter is non- NULL and the function succeeds, the return value is the number of scan lines copied from /// the bitmap. /// /// /// If the lpvBits parameter is NULL and GetDIBits successfully fills the BITMAPINFO structure, the return value is nonzero. /// /// If the function fails, the return value is zero. /// This function can return the following value. /// /// /// Return code /// Description /// /// /// ERROR_INVALID_PARAMETER /// One or more of the input parameters is invalid. /// /// /// /// /// /// If the requested format for the DIB matches its internal format, the RGB values for the bitmap are copied. If the requested /// format doesn't match the internal format, a color table is synthesized. The following table describes the color table synthesized /// for each format. /// /// /// /// Value /// Meaning /// /// /// 1_BPP /// The color table consists of a black and a white entry. /// /// /// 4_BPP /// The color table consists of a mix of colors identical to the standard VGA palette. /// /// /// 8_BPP /// /// The color table consists of a general mix of 256 colors defined by GDI. (Included in these 256 colors are the 20 colors found in /// the default logical palette.) /// /// /// /// 24_BPP /// No color table is returned. /// /// /// /// If the lpvBits parameter is a valid pointer, the first six members of the BITMAPINFOHEADER structure must be initialized to /// specify the size and format of the DIB. The scan lines must be aligned on a DWORD except for RLE compressed bitmaps. /// /// /// A bottom-up DIB is specified by setting the height to a positive number, while a top-down DIB is specified by setting the height /// to a negative number. The bitmap color table will be appended to the BITMAPINFO structure. /// /// /// If lpvBits is NULL, GetDIBits examines the first member of the first structure pointed to by lpbi. This member must /// specify the size, in bytes, of a BITMAPCOREHEADER or a BITMAPINFOHEADER structure. The function uses the specified size to /// determine how the remaining members should be initialized. /// /// /// If lpvBits is NULL and the bit count member of BITMAPINFO is initialized to zero, GetDIBits fills in a /// BITMAPINFOHEADER structure or BITMAPCOREHEADER without the color table. This technique can be used to query bitmap attributes. /// /// /// The bitmap identified by the hbmp parameter must not be selected into a device context when the application calls this function. /// /// /// The origin for a bottom-up DIB is the lower-left corner of the bitmap; the origin for a top-down DIB is the upper-left corner. /// /// Examples /// For an example, see Capturing an Image. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getdibits int GetDIBits( HDC hdc, HBITMAP hbm, UINT start, // UINT cLines, LPVOID lpvBits, LPBITMAPINFO lpbmi, UINT usage ); [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "be3ffa3f-b343-4e38-8b1e-aeccf35d92b8")] public static extern int GetDIBits(HDC hdc, HBITMAP hbm, uint start, uint cLines, ref byte[] lpvBits, ref BITMAPINFO lpbmi, DIBColorMode usage); /// /// The GetDIBits function retrieves the bits of the specified compatible bitmap and copies them into a buffer as a DIB using /// the specified format. /// /// A handle to the device context. /// A handle to the bitmap. This must be a compatible bitmap (DDB). /// The first scan line to retrieve. /// The number of scan lines to retrieve. /// /// A pointer to a buffer to receive the bitmap data. If this parameter is NULL, the function passes the dimensions and format /// of the bitmap to the BITMAPINFO structure pointed to by the lpbi parameter. /// /// A pointer to a BITMAPINFO structure that specifies the desired format for the DIB data. /// /// The format of the bmiColors member of the BITMAPINFO structure. It must be one of the following values. /// /// /// Value /// Meaning /// /// /// DIB_PAL_COLORS /// The color table should consist of an array of 16-bit indexes into the current logical palette. /// /// /// DIB_RGB_COLORS /// The color table should consist of literal red, green, blue (RGB) values. /// /// /// /// /// /// If the lpvBits parameter is non- NULL and the function succeeds, the return value is the number of scan lines copied from /// the bitmap. /// /// /// If the lpvBits parameter is NULL and GetDIBits successfully fills the BITMAPINFO structure, the return value is nonzero. /// /// If the function fails, the return value is zero. /// This function can return the following value. /// /// /// Return code /// Description /// /// /// ERROR_INVALID_PARAMETER /// One or more of the input parameters is invalid. /// /// /// /// /// /// If the requested format for the DIB matches its internal format, the RGB values for the bitmap are copied. If the requested /// format doesn't match the internal format, a color table is synthesized. The following table describes the color table synthesized /// for each format. /// /// /// /// Value /// Meaning /// /// /// 1_BPP /// The color table consists of a black and a white entry. /// /// /// 4_BPP /// The color table consists of a mix of colors identical to the standard VGA palette. /// /// /// 8_BPP /// /// The color table consists of a general mix of 256 colors defined by GDI. (Included in these 256 colors are the 20 colors found in /// the default logical palette.) /// /// /// /// 24_BPP /// No color table is returned. /// /// /// /// If the lpvBits parameter is a valid pointer, the first six members of the BITMAPINFOHEADER structure must be initialized to /// specify the size and format of the DIB. The scan lines must be aligned on a DWORD except for RLE compressed bitmaps. /// /// /// A bottom-up DIB is specified by setting the height to a positive number, while a top-down DIB is specified by setting the height /// to a negative number. The bitmap color table will be appended to the BITMAPINFO structure. /// /// /// If lpvBits is NULL, GetDIBits examines the first member of the first structure pointed to by lpbi. This member must /// specify the size, in bytes, of a BITMAPCOREHEADER or a BITMAPINFOHEADER structure. The function uses the specified size to /// determine how the remaining members should be initialized. /// /// /// If lpvBits is NULL and the bit count member of BITMAPINFO is initialized to zero, GetDIBits fills in a /// BITMAPINFOHEADER structure or BITMAPCOREHEADER without the color table. This technique can be used to query bitmap attributes. /// /// /// The bitmap identified by the hbmp parameter must not be selected into a device context when the application calls this function. /// /// /// The origin for a bottom-up DIB is the lower-left corner of the bitmap; the origin for a top-down DIB is the upper-left corner. /// /// Examples /// For an example, see Capturing an Image. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getdibits int GetDIBits( HDC hdc, HBITMAP hbm, UINT start, // UINT cLines, LPVOID lpvBits, LPBITMAPINFO lpbmi, UINT usage ); [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "be3ffa3f-b343-4e38-8b1e-aeccf35d92b8")] public static extern int GetDIBits(HDC hdc, HBITMAP hbm, uint start, uint cLines, IntPtr lpvBits, ref BITMAPINFO lpbmi, DIBColorMode usage); /// The GetPixel function retrieves the red, green, blue (RGB) color value of the pixel at the specified coordinates. /// A handle to the device context. /// The x-coordinate, in logical units, of the pixel to be examined. /// The y-coordinate, in logical units, of the pixel to be examined. /// /// The return value is the COLORREF value that specifies the RGB of the pixel. If the pixel is outside of the current clipping /// region, the return value is CLR_INVALID (0xFFFFFFFF defined in Wingdi.h). /// /// /// The pixel must be within the boundaries of the current clipping region. /// /// Not all devices support GetPixel. An application should call GetDeviceCaps to determine whether a specified device /// supports this function. /// /// A bitmap must be selected within the device context, otherwise, CLR_INVALID is returned on all pixels. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getpixel COLORREF GetPixel( HDC hdc, int x, int y ); [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "46d17e95-93ce-4a43-b86c-489d6e3afe12")] public static extern COLORREF GetPixel(HDC hdc, int x, int y); /// /// The GetStretchBltMode function retrieves the current stretching mode. The stretching mode defines how color data is added /// to or removed from bitmaps that are stretched or compressed when the StretchBlt function is called. /// /// A handle to the device context. /// /// If the function succeeds, the return value is the current stretching mode. This can be one of the following values. /// /// /// Value /// Description /// /// /// BLACKONWHITE /// /// Performs a Boolean AND operation using the color values for the eliminated and existing pixels. If the bitmap is a monochrome /// bitmap, this mode preserves black pixels at the expense of white pixels. /// /// /// /// COLORONCOLOR /// Deletes the pixels. This mode deletes all eliminated lines of pixels without trying to preserve their information. /// /// /// HALFTONE /// /// Maps pixels from the source rectangle into blocks of pixels in the destination rectangle. The average color over the destination /// block of pixels approximates the color of the source pixels. /// /// /// /// STRETCH_ANDSCANS /// Same as BLACKONWHITE. /// /// /// STRETCH_DELETESCANS /// Same as COLORONCOLOR. /// /// /// STRETCH_HALFTONE /// Same as HALFTONE. /// /// /// STRETCH_ORSCANS /// Same as WHITEONBLACK. /// /// /// WHITEONBLACK /// /// Performs a Boolean OR operation using the color values for the eliminated and existing pixels. If the bitmap is a monochrome /// bitmap, this mode preserves white pixels at the expense of black pixels. /// /// /// /// If the function fails, the return value is zero. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getstretchbltmode int GetStretchBltMode( HDC hdc ); [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "a4408e28-d7ac-44e9-905d-efa75c60e503")] public static extern StretchMode GetStretchBltMode(HDC hdc); /// The GdiGradientFill function fills rectangle and triangle structures. /// A handle to the destination device context. /// A pointer to an array of TRIVERTEX structures that each define a triangle vertex. /// The number of vertices in pVertex. /// /// An array of GRADIENT_TRIANGLE structures in triangle mode, or an array of GRADIENT_RECT structures in rectangle mode. /// /// The number of elements (triangles or rectangles) in pMesh. /// /// The gradient fill mode. This parameter can be one of the following values. /// /// /// Value /// Meaning /// /// /// GRADIENT_FILL_RECT_H /// /// In this mode, two endpoints describe a rectangle. The rectangle is defined to have a constant color (specified by the TRIVERTEX /// structure) for the left and right edges. GDI interpolates the color from the left to right edge and fills the interior. /// /// /// /// GRADIENT_FILL_RECT_V /// /// In this mode, two endpoints describe a rectangle. The rectangle is defined to have a constant color (specified by the TRIVERTEX /// structure) for the top and bottom edges. GDI interpolates the color from the top to bottom edge and fills the interior. /// /// /// /// GRADIENT_FILL_TRIANGLE /// /// In this mode, an array of TRIVERTEX structures is passed to GDI along with a list of array indexes that describe separate /// triangles. GDI performs linear interpolation between triangle vertices and fills the interior. Drawing is done directly in 24- /// and 32-bpp modes. Dithering is performed in 16-, 8-, 4-, and 1-bpp mode. /// /// /// /// /// /// If the function succeeds, the return value is TRUE. /// If the function fails, the return value is FALSE. /// /// /// Note This function is the same as GradientFill. /// /// To add smooth shading to a triangle, call the GdiGradientFill function with the three triangle endpoints. GDI will /// linearly interpolate and fill the triangle. Here is the drawing output of a shaded triangle. /// /// /// To add smooth shading to a rectangle, call GdiGradientFill with the upper-left and lower-right coordinates of the /// rectangle. There are two shading modes used when drawing a rectangle. In horizontal mode, the rectangle is shaded from /// left-to-right. In vertical mode, the rectangle is shaded from top-to-bottom. Here is the drawing output of two shaded rectangles /// - one in horizontal mode, the other in vertical mode. /// /// /// The GdiGradientFill function uses a mesh method to specify the endpoints of the object to draw. All vertices are passed to /// GdiGradientFill in the pVertex array. The pMesh parameter specifies how these vertices are connected to form an object. /// When filling a rectangle, pMesh points to an array of GRADIENT_RECT structures. Each GRADIENT_RECT structure specifies the /// index of two vertices in the pVertex array. These two vertices form the upper-left and lower-right boundary of one rectangle. /// /// /// In the case of filling a triangle, pMesh points to an array of GRADIENT_TRIANGLE structures. Each GRADIENT_TRIANGLE /// structure specifies the index of three vertices in the pVertex array. These three vertices form one triangle. /// /// To simplify hardware acceleration, this routine is not required to be pixel-perfect in the triangle interior. /// /// Note that GdiGradientFill does not use the Alpha member of the TRIVERTEX structure. To use GdiGradientFill with /// transparency, call GdiGradientFill and then call GdiAlphaBlend with the desired values for the alpha channel of each vertex. /// /// For more information, see Smooth Shading, Drawing a Shaded Triangle, and Drawing a Shaded Rectangle. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-gdigradientfill BOOL GdiGradientFill( HDC hdc, PTRIVERTEX // pVertex, ULONG nVertex, PVOID pMesh, ULONG nCount, ULONG ulMode ); [DllImport(Lib.Gdi32, SetLastError = false, EntryPoint = "GradientFill")] [PInvokeData("wingdi.h", MSDNShortId = "c88c1137-5690-4139-9d10-90d036e8f31c")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GradientFill(HDC hdc, TRIVERTEX[] pVertex, uint nVertex, GRADIENT_TRIANGLE[] pMesh, uint nCount, GradientFillMode ulMode); /// /// The MaskBlt function combines the color data for the source and destination bitmaps using the specified mask and raster operation. /// /// A handle to the destination device context. /// The x-coordinate, in logical units, of the upper-left corner of the destination rectangle. /// The y-coordinate, in logical units, of the upper-left corner of the destination rectangle. /// The width, in logical units, of the destination rectangle and source bitmap. /// The height, in logical units, of the destination rectangle and source bitmap. /// /// A handle to the device context from which the bitmap is to be copied. It must be zero if the dwRop parameter specifies a raster /// operation that does not include a source. /// /// The x-coordinate, in logical units, of the upper-left corner of the source bitmap. /// The y-coordinate, in logical units, of the upper-left corner of the source bitmap. /// A handle to the monochrome mask bitmap combined with the color bitmap in the source device context. /// The horizontal pixel offset for the mask bitmap specified by the hbmMask parameter. /// The vertical pixel offset for the mask bitmap specified by the hbmMask parameter. /// /// /// The foreground and background ternary raster operation codes (ROPs) that the function uses to control the combination of source /// and destination data. The background raster operation code is stored in the high-order byte of the high-order word of this value; /// the foreground raster operation code is stored in the low-order byte of the high-order word of this value; the low-order word of /// this value is ignored, and should be zero. The macro MAKEROP4 creates such combinations of foreground and background raster /// operation codes. /// /// For a discussion of foreground and background in the context of this function, see the following Remarks section. /// /// For a list of common raster operation codes (ROPs), see the BitBlt function. Note that the CAPTUREBLT ROP generally cannot be /// used for printing device contexts. /// /// /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. /// /// /// The MaskBlt function uses device-dependent bitmaps. /// /// A value of 1 in the mask specified by hbmMask indicates that the foreground raster operation code specified by dwRop should be /// applied at that location. A value of 0 in the mask indicates that the background raster operation code specified by dwRop should /// be applied at that location. /// /// /// If the raster operations require a source, the mask rectangle must cover the source rectangle. If it does not, the function will /// fail. If the raster operations do not require a source, the mask rectangle must cover the destination rectangle. If it does not, /// the function will fail. /// /// /// If a rotation or shear transformation is in effect for the source device context when this function is called, an error occurs. /// However, other types of transformation are allowed. /// /// /// If the color formats of the source, pattern, and destination bitmaps differ, this function converts the pattern or source format, /// or both, to match the destination format. /// /// If the mask bitmap is not a monochrome bitmap, an error occurs. /// /// When an enhanced metafile is being recorded, an error occurs (and the function returns FALSE) if the source device context /// identifies an enhanced-metafile device context. /// /// /// Not all devices support the MaskBlt function. An application should call the GetDeviceCaps function with the nIndex /// parameter as RC_BITBLT to determine whether a device supports this function. /// /// If no mask bitmap is supplied, this function behaves exactly like BitBlt, using the foreground raster operation code. /// ICM: No color management is performed when blits occur. /// /// When used in a multiple monitor system, both hdcSrc and hdcDest must refer to the same device or the function will fail. To /// transfer data between DCs for different devices, convert the memory bitmap (compatible bitmap, or DDB) to a DIB by calling /// GetDIBits. To display the DIB to the second device, call SetDIBits or StretchDIBits. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-maskblt BOOL MaskBlt( HDC hdcDest, int xDest, int yDest, int // width, int height, HDC hdcSrc, int xSrc, int ySrc, HBITMAP hbmMask, int xMask, int yMask, DWORD rop ); [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "9fd6f0ce-a802-428d-9be5-a66afe39e9b7")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool MaskBlt(HDC hdcDest, int xDest, int yDest, int width, int height, HDC hdcSrc, int xSrc, int ySrc, HBITMAP hbmMask, int xMask, int yMask, RasterOperationMode rop); /// /// The PlgBlt function performs a bit-block transfer of the bits of color data from the specified rectangle in the source /// device context to the specified parallelogram in the destination device context. If the given bitmask handle identifies a valid /// monochrome bitmap, the function uses this bitmap to mask the bits of color data from the source rectangle. /// /// A handle to the destination device context. /// /// A pointer to an array of three points in logical space that identify three corners of the destination parallelogram. The /// upper-left corner of the source rectangle is mapped to the first point in this array, the upper-right corner to the second point /// in this array, and the lower-left corner to the third point. The lower-right corner of the source rectangle is mapped to the /// implicit fourth point in the parallelogram. /// /// A handle to the source device context. /// The x-coordinate, in logical units, of the upper-left corner of the source rectangle. /// The y-coordinate, in logical units, of the upper-left corner of the source rectangle. /// The width, in logical units, of the source rectangle. /// The height, in logical units, of the source rectangle. /// A handle to an optional monochrome bitmap that is used to mask the colors of the source rectangle. /// The x-coordinate, in logical units, of the upper-left corner of the monochrome bitmap. /// The y-coordinate, in logical units, of the upper-left corner of the monochrome bitmap. /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. /// /// /// The PlgBlt function works with device-dependent bitmaps. /// /// The fourth vertex of the parallelogram (D) is defined by treating the first three points (A, B, and C ) as vectors and computing /// D = B +CA. /// /// /// If the bitmask exists, a value of one in the mask indicates that the source pixel color should be copied to the destination. A /// value of zero in the mask indicates that the destination pixel color is not to be changed. If the mask rectangle is smaller than /// the source and destination rectangles, the function replicates the mask pattern. /// /// /// Scaling, translation, and reflection transformations are allowed in the source device context; however, rotation and shear /// transformations are not. If the mask bitmap is not a monochrome bitmap, an error occurs. The stretching mode for the destination /// device context is used to determine how to stretch or compress the pixels, if that is necessary. /// /// /// When an enhanced metafile is being recorded, an error occurs if the source device context identifies an enhanced-metafile device context. /// /// /// The destination coordinates are transformed according to the destination device context; the source coordinates are transformed /// according to the source device context. If the source transformation has a rotation or shear, an error is returned. /// /// /// If the destination and source rectangles do not have the same color format, PlgBlt converts the source rectangle to match /// the destination rectangle. /// /// /// Not all devices support the PlgBlt function. For more information, see the description of the RC_BITBLT raster capability /// in the GetDeviceCaps function. /// /// If the source and destination device contexts represent incompatible devices, PlgBlt returns an error. /// /// When used in a multiple monitor system, both hdcSrc and hdcDest must refer to the same device or the function will fail. To /// transfer data between DCs for different devices, convert the memory bitmap to a DIB by calling GetDIBits. To display the DIB to /// the second device, call SetDIBits or StretchDIBits. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-plgblt BOOL PlgBlt( HDC hdcDest, const POINT *lpPoint, HDC // hdcSrc, int xSrc, int ySrc, int width, int height, HBITMAP hbmMask, int xMask, int yMask ); [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "2a56c71b-2e96-418b-8625-a808d76e0c85")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool PlgBlt(HDC hdcDest, [In, MarshalAs(UnmanagedType.LPArray, SizeConst = 3)] System.Drawing.Point[] lpPoint, HDC hdcSrc, int xSrc, int ySrc, int width, int height, HBITMAP hbmMask, int xMask, int yMask); /// /// The SetBitmapBits function sets the bits of color data for a bitmap to the specified values. /// /// Note This function is provided only for compatibility with 16-bit versions of Windows. Applications should use the /// SetDIBits function. /// /// /// A handle to the bitmap to be set. This must be a compatible bitmap (DDB). /// The number of bytes pointed to by the lpBits parameter. /// A pointer to an array of bytes that contain color data for the specified bitmap. /// /// If the function succeeds, the return value is the number of bytes used in setting the bitmap bits. /// If the function fails, the return value is zero. /// /// The array identified by lpBits must be WORD aligned. // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-setbitmapbits LONG SetBitmapBits( HBITMAP hbm, DWORD cb, const // VOID *pvBits ); [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "3cab12a6-c408-4552-bec0-5ecfd8374757")] public static extern int SetBitmapBits(HBITMAP hbm, uint cb, byte[] pvBits); /// /// The SetBitmapDimensionEx function assigns preferred dimensions to a bitmap. These dimensions can be used by applications; /// however, they are not used by the system. /// /// A handle to the bitmap. The bitmap cannot be a DIB-section bitmap. /// The width, in 0.1-millimeter units, of the bitmap. /// The height, in 0.1-millimeter units, of the bitmap. /// A pointer to a SIZE structure to receive the previous dimensions of the bitmap. This pointer can be NULL. /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. /// /// /// /// An application can retrieve the dimensions assigned to a bitmap with the SetBitmapDimensionEx function by calling the /// GetBitmapDimensionEx function. /// /// /// The bitmap identified by hBitmap cannot be a DIB section, which is a bitmap created by the CreateDIBSection function. If the /// bitmap is a DIB section, the SetBitmapDimensionEx function fails. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-setbitmapdimensionex BOOL SetBitmapDimensionEx( HBITMAP hbm, // int w, int h, LPSIZE lpsz ); [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "23960533-de71-4bff-a43f-75e5fe38fbec")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetBitmapDimensionEx(HBITMAP hbm, int w, int h, out SIZE lpsz); /// /// The SetDIBColorTable function sets RGB (red, green, blue) color values in a range of entries in the color table of the DIB /// that is currently selected into a specified device context. /// /// A device context. A DIB must be selected into this device context. /// A zero-based color table index that specifies the first color table entry to set. /// The number of color table entries to set. /// A pointer to an array of RGBQUAD structures containing new color information for the DIB's color table. /// /// If the function succeeds, the return value is the number of color table entries that the function sets. /// If the function fails, the return value is zero. /// /// /// /// This function should be called to set the color table for DIBs that use 1, 4, or 8 bpp. The BitCount member of a bitmap's /// associated bitmap information header structure. /// /// /// BITMAPINFOHEADER structure specifies the number of bits-per-pixel. Device-independent bitmaps with a biBitCount value /// greater than 8 do not have a color table. /// /// /// The bV5BitCount member of a bitmap's associated BITMAPV5HEADER structure specifies the number of bits-per-pixel. /// Device-independent bitmaps with a bV5BitCount value greater than 8 do not have a color table. /// /// ICM: No color management is performed. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-setdibcolortable UINT SetDIBColorTable( HDC hdc, UINT iStart, // UINT cEntries, const RGBQUAD *prgbq ); [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "f301c34d-6e8e-4dc8-b3f3-0fdc658d09e3")] public static extern uint SetDIBColorTable(HDC hdc, uint iStart, uint cEntries, [In] RGBQUAD[] prgbq); /// /// The SetDIBits function sets the pixels in a compatible bitmap (DDB) using the color data found in the specified DIB. /// /// A handle to a device context. /// A handle to the compatible bitmap (DDB) that is to be altered using the color data from the specified DIB. /// The starting scan line for the device-independent color data in the array pointed to by the lpvBits parameter. /// The number of scan lines found in the array containing device-independent color data. /// /// A pointer to the DIB color data, stored as an array of bytes. The format of the bitmap values depends on the biBitCount /// member of the BITMAPINFO structure pointed to by the lpbmi parameter. /// /// A pointer to a BITMAPINFO structure that contains information about the DIB. /// /// /// Indicates whether the bmiColors member of the BITMAPINFO structure was provided and, if so, whether bmiColors /// contains explicit red, green, blue (RGB) values or palette indexes. The fuColorUse parameter must be one of the following values. /// /// /// /// Value /// Meaning /// /// /// DIB_PAL_COLORS /// /// The color table consists of an array of 16-bit indexes into the logical palette of the device context identified by the hdc parameter. /// /// /// /// DIB_RGB_COLORS /// The color table is provided and contains literal RGB values. /// /// /// /// /// If the function succeeds, the return value is the number of scan lines copied. /// If the function fails, the return value is zero. /// This can be the following value. /// /// /// Return code /// Description /// /// /// ERROR_INVALID_PARAMETER /// One or more of the input parameters is invalid. /// /// /// /// /// Optimal bitmap drawing speed is obtained when the bitmap bits are indexes into the system palette. /// /// Applications can retrieve the system palette colors and indexes by calling the GetSystemPaletteEntries function. After the colors /// and indexes are retrieved, the application can create the DIB. For more information, see System Palette. /// /// /// The device context identified by the hdc parameter is used only if the DIB_PAL_COLORS constant is set for the fuColorUse /// parameter; otherwise it is ignored. /// /// /// The bitmap identified by the hbmp parameter must not be selected into a device context when the application calls this function. /// /// The scan lines must be aligned on a DWORD except for RLE-compressed bitmaps. /// /// The origin for bottom-up DIBs is the lower-left corner of the bitmap; the origin for top-down DIBs is the upper-left corner of /// the bitmap. /// /// /// ICM: Color management is performed if color management has been enabled with a call to SetICMMode with the iEnableICM /// parameter set to ICM_ON. If the bitmap specified by lpbmi has a BITMAPV4HEADER that specifies the gamma and endpoints members, or /// a BITMAPV5HEADER that specifies either the gamma and endpoints members or the profileData and profileSize members, then the call /// treats the bitmap's pixels as being expressed in the color space described by those members, rather than in the device context's /// source color space. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-setdibits int SetDIBits( HDC hdc, HBITMAP hbm, UINT start, // UINT cLines, const VOID *lpBits, const BITMAPINFO *lpbmi, UINT ColorUse ); [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "706f4532-4073-4d5c-ae2d-e33aea9163e9")] public static extern int SetDIBits(HDC hdc, HBITMAP hbm, uint start, uint cLines, byte[] lpBits, ref BITMAPINFO lpbmi, DIBColorMode ColorUse); /// /// The SetDIBitsToDevice function sets the pixels in the specified rectangle on the device that is associated with the /// destination device context using color data from a DIB, JPEG, or PNG image. /// /// A handle to the device context. /// The x-coordinate, in logical units, of the upper-left corner of the destination rectangle. /// The y-coordinate, in logical units, of the upper-left corner of the destination rectangle. /// The width, in logical units, of the image. /// The height, in logical units, of the image. /// The x-coordinate, in logical units, of the lower-left corner of the image. /// The y-coordinate, in logical units, of the lower-left corner of the image. /// The starting scan line in the image. /// The number of DIB scan lines contained in the array pointed to by the lpvBits parameter. /// /// A pointer to the color data stored as an array of bytes. For more information, see the following Remarks section. /// /// A pointer to a BITMAPINFO structure that contains information about the DIB. /// /// /// Indicates whether the bmiColors member of the BITMAPINFO structure contains explicit red, green, blue (RGB) values or /// indexes into a palette. For more information, see the following Remarks section. /// /// The fuColorUse parameter must be one of the following values. /// /// /// Value /// Meaning /// /// /// DIB_PAL_COLORS /// The color table consists of an array of 16-bit indexes into the currently selected logical palette. /// /// /// DIB_RGB_COLORS /// The color table contains literal RGB values. /// /// /// /// /// If the function succeeds, the return value is the number of scan lines set. /// If zero scan lines are set (such as when dwHeight is 0) or the function fails, the function returns zero. /// /// If the driver cannot support the JPEG or PNG file image passed to SetDIBitsToDevice, the function will fail and return /// GDI_ERROR. If failure does occur, the application must fall back on its own JPEG or PNG support to decompress the image into a /// bitmap, and then pass the bitmap to SetDIBitsToDevice. /// /// /// /// Optimal bitmap drawing speed is obtained when the bitmap bits are indexes into the system palette. /// /// Applications can retrieve the system palette colors and indexes by calling the GetSystemPaletteEntries function. After the colors /// and indexes are retrieved, the application can create the DIB. For more information about the system palette, see Colors. /// /// The scan lines must be aligned on a DWORD except for RLE-compressed bitmaps. /// The origin of a bottom-up DIB is the lower-left corner of the bitmap; the origin of a top-down DIB is the upper-left corner. /// /// To reduce the amount of memory required to set bits from a large DIB on a device surface, an application can band the output by /// repeatedly calling SetDIBitsToDevice, placing a different portion of the bitmap into the lpvBits array each time. The /// values of the uStartScan and cScanLines parameters identify the portion of the bitmap contained in the lpvBits array. /// /// /// The SetDIBitsToDevice function returns an error if it is called by a process that is running in the background while a /// full-screen MS-DOS session runs in the foreground. /// /// /// /// /// If the biCompression member of BITMAPINFOHEADER is BI_JPEG or BI_PNG, lpvBits points to a buffer containing a JPEG or PNG /// image. The biSizeImage member of specifies the size of the buffer. The fuColorUse parameter must be set to DIB_RGB_COLORS. /// /// /// /// /// To ensure proper metafile spooling while printing, applications must call the CHECKJPEGFORMAT or CHECKPNGFORMAT escape to verify /// that the printer recognizes the JPEG or PNG image, respectively, before calling SetDIBitsToDevice. /// /// /// /// /// ICM: Color management is performed if color management has been enabled with a call to SetICMMode with the iEnableICM /// parameter set to ICM_ON. If the bitmap specified by lpbmi has a BITMAPV4HEADER that specifies the gamma and endpoints members, or /// a BITMAPV5HEADER that specifies either the gamma and endpoints members or the profileData and profileSize members, then the call /// treats the bitmap's pixels as being expressed in the color space described by those members, rather than in the device context's /// source color space. /// /// Examples /// For an example, see Testing a Printer for JPEG or PNG Support. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-setdibitstodevice int SetDIBitsToDevice( HDC hdc, int xDest, // int yDest, DWORD w, DWORD h, int xSrc, int ySrc, UINT StartScan, UINT cLines, const VOID *lpvBits, const BITMAPINFO *lpbmi, UINT // ColorUse ); [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "41225400-12e3-47ba-8b88-ac1d5b0fa90f")] public static extern int SetDIBitsToDevice(HDC hdc, int xDest, int yDest, uint w, uint h, int xSrc, int ySrc, uint StartScan, uint cLines, byte[] lpvBits, ref BITMAPINFO lpbmi, DIBColorMode ColorUse); /// The SetPixel function sets the pixel at the specified coordinates to the specified color. /// A handle to the device context. /// The x-coordinate, in logical units, of the point to be set. /// The y-coordinate, in logical units, of the point to be set. /// The color to be used to paint the point. To create a COLORREF color value, use the RGB macro. /// /// /// If the function succeeds, the return value is the RGB value that the function sets the pixel to. This value may differ from the /// color specified by crColor; that occurs when an exact match for the specified color cannot be found. /// /// If the function fails, the return value is -1. /// This can be the following value. /// /// /// Return code /// Description /// /// /// ERROR_INVALID_PARAMETER /// One or more of the input parameters is invalid. /// /// /// /// /// The function fails if the pixel coordinates lie outside of the current clipping region. /// Not all devices support the SetPixel function. For more information, see GetDeviceCaps. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-setpixel COLORREF SetPixel( HDC hdc, int x, int y, COLORREF // color ); [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "652e2e7a-79ae-4668-b269-153ee08a5de9")] public static extern COLORREF SetPixel(HDC hdc, int x, int y, COLORREF color); /// /// The SetPixelV function sets the pixel at the specified coordinates to the closest approximation of the specified color. /// The point must be in the clipping region and the visible part of the device surface. /// /// A handle to the device context. /// The x-coordinate, in logical units, of the point to be set. /// The y-coordinate, in logical units, of the point to be set. /// The color to be used to paint the point. To create a COLORREF color value, use the RGB macro. /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. /// /// /// /// Not all devices support the SetPixelV function. For more information, see the description of the RC_BITBLT capability in /// the GetDeviceCaps function. /// /// SetPixelV is faster than SetPixel because it does not need to return the color value of the point actually painted. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-setpixelv BOOL SetPixelV( HDC hdc, int x, int y, COLORREF // color ); [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "638f0ffd-3771-4390-b335-0517be5312fd")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetPixelV(HDC hdc, int x, int y, COLORREF color); /// The SetStretchBltMode function sets the bitmap stretching mode in the specified device context. /// A handle to the device context. /// /// The stretching mode. This parameter can be one of the following values. /// /// /// Value /// Meaning /// /// /// BLACKONWHITE /// /// Performs a Boolean AND operation using the color values for the eliminated and existing pixels. If the bitmap is a monochrome /// bitmap, this mode preserves black pixels at the expense of white pixels. /// /// /// /// COLORONCOLOR /// Deletes the pixels. This mode deletes all eliminated lines of pixels without trying to preserve their information. /// /// /// HALFTONE /// /// Maps pixels from the source rectangle into blocks of pixels in the destination rectangle. The average color over the destination /// block of pixels approximates the color of the source pixels. After setting the HALFTONE stretching mode, an application must call /// the SetBrushOrgEx function to set the brush origin. If it fails to do so, brush misalignment occurs. /// /// /// /// STRETCH_ANDSCANS /// Same as BLACKONWHITE. /// /// /// STRETCH_DELETESCANS /// Same as COLORONCOLOR. /// /// /// STRETCH_HALFTONE /// Same as HALFTONE. /// /// /// STRETCH_ORSCANS /// Same as WHITEONBLACK. /// /// /// WHITEONBLACK /// /// Performs a Boolean OR operation using the color values for the eliminated and existing pixels. If the bitmap is a monochrome /// bitmap, this mode preserves white pixels at the expense of black pixels. /// /// /// /// /// /// If the function succeeds, the return value is the previous stretching mode. /// If the function fails, the return value is zero. /// This function can return the following value. /// /// /// Return code /// Description /// /// /// ERROR_INVALID_PARAMETER /// One or more of the input parameters is invalid. /// /// /// /// /// /// The stretching mode defines how the system combines rows or columns of a bitmap with existing pixels on a display device when an /// application calls the StretchBlt function. /// /// /// The BLACKONWHITE (STRETCH_ANDSCANS) and WHITEONBLACK (STRETCH_ORSCANS) modes are typically used to preserve foreground pixels in /// monochrome bitmaps. The COLORONCOLOR (STRETCH_DELETESCANS) mode is typically used to preserve color in color bitmaps. /// /// /// The HALFTONE mode is slower and requires more processing of the source image than the other three modes; but produces higher /// quality images. Also note that SetBrushOrgEx must be called after setting the HALFTONE mode to avoid brush misalignment. /// /// Additional stretching modes might also be available depending on the capabilities of the device driver. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-setstretchbltmode // int SetStretchBltMode( HDC hdc, int mode ); [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "3e5a48dc-ccd5-41ea-a24b-5c40213abf38")] public static extern StretchMode SetStretchBltMode(HDC hdc, StretchMode mode); /// /// The StretchBlt function copies a bitmap from a source rectangle into a destination rectangle, stretching or compressing /// the bitmap to fit the dimensions of the destination rectangle, if necessary. The system stretches or compresses the bitmap /// according to the stretching mode currently set in the destination device context. /// /// A handle to the destination device context. /// The x-coordinate, in logical units, of the upper-left corner of the destination rectangle. /// The y-coordinate, in logical units, of the upper-left corner of the destination rectangle. /// The width, in logical units, of the destination rectangle. /// The height, in logical units, of the destination rectangle. /// A handle to the source device context. /// The x-coordinate, in logical units, of the upper-left corner of the source rectangle. /// The y-coordinate, in logical units, of the upper-left corner of the source rectangle. /// The width, in logical units, of the source rectangle. /// The height, in logical units, of the source rectangle. /// /// /// The raster operation to be performed. Raster operation codes define how the system combines colors in output operations that /// involve a brush, a source bitmap, and a destination bitmap. /// /// /// See BitBlt for a list of common raster operation codes (ROPs). Note that the CAPTUREBLT ROP generally cannot be used for printing /// device contexts. /// /// /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. /// /// /// /// StretchBlt stretches or compresses the source bitmap in memory and then copies the result to the destination rectangle. /// This bitmap can be either a compatible bitmap (DDB) or the output from CreateDIBSection. The color data for pattern or /// destination pixels is merged after the stretching or compression occurs. /// /// /// When an enhanced metafile is being recorded, an error occurs (and the function returns FALSE) if the source device context /// identifies an enhanced-metafile device context. /// /// /// If the specified raster operation requires a brush, the system uses the brush currently selected into the destination device context. /// /// /// The destination coordinates are transformed by using the transformation currently specified for the destination device context; /// the source coordinates are transformed by using the transformation currently specified for the source device context. /// /// If the source transformation has a rotation or shear, an error occurs. /// /// If destination, source, and pattern bitmaps do not have the same color format, StretchBlt converts the source and pattern /// bitmaps to match the destination bitmap. /// /// /// If StretchBlt must convert a monochrome bitmap to a color bitmap, it sets white bits (1) to the background color and black /// bits (0) to the foreground color. To convert a color bitmap to a monochrome bitmap, it sets pixels that match the background /// color to white (1) and sets all other pixels to black (0). The foreground and background colors of the device context with color /// are used. /// /// /// StretchBlt creates a mirror image of a bitmap if the signs of the nWidthSrc and nWidthDest parameters or if the nHeightSrc /// and nHeightDest parameters differ. If nWidthSrc and nWidthDest have different signs, the function creates a mirror image of the /// bitmap along the x-axis. If nHeightSrc and nHeightDest have different signs, the function creates a mirror image of the bitmap /// along the y-axis. /// /// Not all devices support the StretchBlt function. For more information, see the GetDeviceCaps. /// ICM: No color management is performed when a blit operation occurs. /// /// When used in a multiple monitor system, both hdcSrc and hdcDest must refer to the same device or the function will fail. To /// transfer data between DCs for different devices, convert the memory bitmap to a DIB by calling GetDIBits. To display the DIB to /// the second device, call SetDIBits or StretchDIBits. /// /// Examples /// For an example, see Scaling an Image. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-stretchblt BOOL StretchBlt( HDC hdcDest, int xDest, int yDest, // int wDest, int hDest, HDC hdcSrc, int xSrc, int ySrc, int wSrc, int hSrc, DWORD rop ); [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "5130c88e-08e8-4faa-a1cb-a8106c86cea0")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool StretchBlt(HDC hdcDest, int xDest, int yDest, int wDest, int hDest, HDC hdcSrc, int xSrc, int ySrc, int wSrc, int hSrc, RasterOperationMode rop); /// /// The StretchDIBits function copies the color data for a rectangle of pixels in a DIB, JPEG, or PNG image to the specified /// destination rectangle. If the destination rectangle is larger than the source rectangle, this function stretches the rows and /// columns of color data to fit the destination rectangle. If the destination rectangle is smaller than the source rectangle, this /// function compresses the rows and columns by using the specified raster operation. /// /// A handle to the destination device context. /// The x-coordinate, in logical units, of the upper-left corner of the destination rectangle. /// The y-coordinate, in logical units, of the upper-left corner of the destination rectangle. /// The width, in logical units, of the destination rectangle. /// The height, in logical units, of the destination rectangle. /// The x-coordinate, in pixels, of the source rectangle in the image. /// The y-coordinate, in pixels, of the source rectangle in the image. /// The width, in pixels, of the source rectangle in the image. /// The height, in pixels, of the source rectangle in the image. /// /// A pointer to the image bits, which are stored as an array of bytes. For more information, see the Remarks section. /// /// A pointer to a BITMAPINFO structure that contains information about the DIB. /// /// /// Specifies whether the bmiColors member of the BITMAPINFO structure was provided and, if so, whether bmiColors /// contains explicit red, green, blue (RGB) values or indexes. The iUsage parameter must be one of the following values. /// /// /// /// Value /// Meaning /// /// /// DIB_PAL_COLORS /// The array contains 16-bit indexes into the logical palette of the source device context. /// /// /// DIB_RGB_COLORS /// The color table contains literal RGB values. /// /// /// For more information, see the Remarks section. /// /// /// A raster-operation code that specifies how the source pixels, the destination device context's current brush, and the destination /// pixels are to be combined to form the new image. For a list of some common raster operation codes, see BitBlt. /// /// /// /// If the function succeeds, the return value is the number of scan lines copied. Note that this value can be negative for mirrored content. /// /// If the function fails, or no scan lines are copied, the return value is 0. /// /// If the driver cannot support the JPEG or PNG file image passed to StretchDIBits, the function will fail and return /// GDI_ERROR. If failure does occur, the application must fall back on its own JPEG or PNG support to decompress the image into a /// bitmap, and then pass the bitmap to StretchDIBits. /// /// /// /// The origin of a bottom-up DIB is the lower-left corner; the origin of a top-down DIB is the upper-left corner. /// /// StretchDIBits creates a mirror image of a bitmap if the signs of the nSrcWidth and nDestWidth parameters, or if the /// nSrcHeight and nDestHeight parameters differ. If nSrcWidth and nDestWidth have different signs, the function creates a mirror /// image of the bitmap along the x-axis. If nSrcHeight and nDestHeight have different signs, the function creates a mirror image of /// the bitmap along the y-axis. /// /// /// StretchDIBits creates a top-down image if the sign of the biHeight member of the BITMAPINFOHEADER structure for the /// DIB is negative. For a code example, see Sizing a JPEG or PNG Image. /// /// /// This function allows a JPEG or PNG image to be passed as the source image. How each parameter is used remains the same, except: /// /// /// /// /// If the biCompression member of BITMAPINFOHEADER is BI_JPEG or BI_PNG, lpBits points to a buffer containing a JPEG or PNG /// image, respectively. The biSizeImage member of the BITMAPINFOHEADER structure specifies the size of the buffer. The /// iUsage parameter must be set to DIB_RGB_COLORS. The dwRop parameter must be set to SRCCOPY. /// /// /// /// /// To ensure proper metafile spooling while printing, applications must call the CHECKJPEGFORMAT or CHECKPNGFORMAT escape to verify /// that the printer recognizes the JPEG or PNG image, respectively, before calling StretchDIBits. /// /// /// /// /// ICM: Color management is performed if color management has been enabled with a call to SetICMMode with the iEnableICM /// parameter set to ICM_ON. If the bitmap specified by lpBitsInfo has a BITMAPV4HEADER that specifies the gamma and endpoints /// members, or a BITMAPV5HEADER that specifies either the gamma and endpoints members or the profileData and profileSize members, /// then the call treats the bitmap's pixels as being expressed in the color space described by those members, rather than in the /// device context's source color space. /// /// Examples /// For an example, see Sizing a JPEG or PNG Image. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-stretchdibits int StretchDIBits( HDC hdc, int xDest, int // yDest, int DestWidth, int DestHeight, int xSrc, int ySrc, int SrcWidth, int SrcHeight, const VOID *lpBits, const BITMAPINFO // *lpbmi, UINT iUsage, DWORD rop ); [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "3d57a79a-338d-48ab-8161-3ce17739bf20")] public static extern int StretchDIBits(HDC hdc, int xDest, int yDest, int DestWidth, int DestHeight, int xSrc, int ySrc, int SrcWidth, int SrcHeight, byte[] lpBits, ref BITMAPINFO lpbmi, DIBColorMode iUsage, RasterOperationMode rop); /// /// /// The GdiTransparentBlt function performs a bit-block transfer of the color data corresponding to a rectangle of pixels from /// the specified source device context into a destination device context. /// /// Note This function is the same as TransparentBlt. /// /// A handle to the destination device context. /// The x-coordinate, in logical units, of the upper-left corner of the destination rectangle. /// The y-coordinate, in logical units, of the upper-left corner of the destination rectangle. /// The width, in logical units, of the destination rectangle. /// The height, in logical units, of the destination rectangle. /// A handle to the source device context. /// The x-coordinate, in logical units, of the source rectangle. /// The y-coordinate, in logical units, of the source rectangle. /// The width, in logical units, of the source rectangle. /// The height, in logical units, of the source rectangle. /// The RGB color in the source bitmap to treat as transparent. /// /// If the function succeeds, the return value is TRUE. /// If the function fails, the return value is FALSE. /// /// /// The GdiTransparentBlt function works with compatible bitmaps (DDBs). /// /// The GdiTransparentBlt function supports all formats of source bitmaps. However, for 32 bpp bitmaps, it just copies the alpha /// value over. Use AlphaBlend to specify 32 bits-per-pixel bitmaps with transparency. /// /// /// If the source and destination rectangles are not the same size, the source bitmap is stretched to match the destination /// rectangle. When the SetStretchBltMode function is used, the iStretchMode modes of BLACKONWHITE and WHITEONBLACK are converted to /// COLORONCOLOR for the GdiTransparentBlt function. /// /// /// The destination device context specifies the transformation type for the destination coordinates. The source device context /// specifies the transformation type for the source coordinates. /// /// /// GdiTransparentBlt does not mirror a bitmap if either the width or height, of either the source or destination, is negative. /// /// /// When used in a multiple monitor system, both hdcSrc and hdcDest must refer to the same device or the function will fail. To /// transfer data between DCs for different devices, convert the memory bitmap to a DIB by calling GetDIBits. To display the DIB to /// the second device, call SetDIBits or StretchDIBits. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-gditransparentblt BOOL GdiTransparentBlt( HDC hdcDest, int // xoriginDest, int yoriginDest, int wDest, int hDest, HDC hdcSrc, int xoriginSrc, int yoriginSrc, int wSrc, int hSrc, UINT // crTransparent ); [PInvokeData("wingdi.h", MSDNShortId = "82f6db79-f364-480a-ad9d-acf2ad94a295")] [DllImport(Lib.Gdi32, SetLastError = true, EntryPoint = "GdiTransparentBlt")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool TransparentBlt(HDC hdcDest, int xoriginDest, int yoriginDest, int wDest, int hDest, HDC hdcSrc, int xoriginSrc, int yoriginSrc, int wSrc, int hSrc, uint crTransparent); /// /// The GRADIENT_TRIANGLE structure specifies the index of three vertices in the pVertex array in the GradientFill /// function. These three vertices form one triangle. /// /// /// /// The GRADIENT_TRIANGLE structure specifies the values in the pVertex array that are used when the dwMode parameter of the /// GradientFill function is GRADIENT_FILL_TRIANGLE. For related GradientFill structures, see GRADIENT_RECT and TRIVERTEX. /// /// The following image shows an example of a triangle with a gradient fill. /// Examples /// For an example, see Drawing a Shaded Triangle. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-gradient_triangle typedef struct _GRADIENT_TRIANGLE { ULONG // Vertex1; ULONG Vertex2; ULONG Vertex3; } GRADIENT_TRIANGLE, *PGRADIENT_TRIANGLE, *LPGRADIENT_TRIANGLE; [PInvokeData("wingdi.h", MSDNShortId = "71f3a4bd-5823-47ae-aa7a-f3058f18c591")] [StructLayout(LayoutKind.Sequential)] public struct GRADIENT_TRIANGLE { /// The first point of the triangle where sides intersect. public uint Vertex1; /// The second point of the triangle where sides intersect. public uint Vertex2; /// The third point of the triangle where sides intersect. public uint Vertex3; } /// Provides a handle to a DIB section. [StructLayout(LayoutKind.Sequential)] public struct HSECTION : IHandle { private IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public HSECTION(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static HSECTION NULL => new HSECTION(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(HSECTION h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator HSECTION(IntPtr h) => new HSECTION(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(HSECTION h1, HSECTION h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(HSECTION h1, HSECTION h2) => h1.Equals(h2); /// public override bool Equals(object obj) => obj is HSECTION h ? handle == h.handle : false; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// The TRIVERTEX structure contains color information and position information. /// /// /// In the TRIVERTEX structure, x and y indicate position in the same manner as in the POINTL structure contained in the /// wtypes.h header file. Red, Green, Blue, and Alpha members indicate color information at the point x, /// y. The color information of each channel is specified as a value from 0x0000 to 0xff00. This allows higher color resolution for /// an object that has been split into small triangles for display. The TRIVERTEX structure contains information needed by the /// pVertex parameter of GradientFill. /// /// Examples /// For an example of the use of this structure, see Drawing a Shaded Triangle or Drawing a Shaded Rectangle. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-trivertex typedef struct _TRIVERTEX { LONG x; LONG y; COLOR16 // Red; COLOR16 Green; COLOR16 Blue; COLOR16 Alpha; } TRIVERTEX, *PTRIVERTEX, *LPTRIVERTEX; [PInvokeData("wingdi.h", MSDNShortId = "47b700aa-3410-4610-ba06-dab2b2662f5e")] [StructLayout(LayoutKind.Sequential)] public struct TRIVERTEX { /// The x-coordinate, in logical units, of the upper-left corner of the rectangle. public int x; /// The y-coordinate, in logical units, of the upper-left corner of the rectangle. public int y; /// The color information at the point of x, y. public ushort Red; /// The color information at the point of x, y. public ushort Green; /// The color information at the point of x, y. public ushort Blue; /// The color information at the point of x, y. public ushort Alpha; } } }