Help Center

GdipGetImageAttributesAdjustedPalettefunction

Adjusts the colors in a palette according to the adjustment settings of a specified category.

Graphicsfunctiondocumented

Syntax

FUNCTION GdipGetImageAttributesAdjustedPalette (BYVAL imageattr AS GpImageAttributes PTR, BYVAL colorPalette AS ColorPalette PTR, BYVAL colorAdjustType AS ColorAdjustType) AS GpStatus

Parameters

NameDescription
imageattr[in] Pointer to the ImageAttributes object.
colorPalette[in, out] Pointer to a ColorPalette structure that on input, contains the palette to be adjusted and, on output, receives the adjusted palette.
colorAdjustType[in] Element of the ColorAdjustType enumeration that specifies the category whose adjustment settings will be applied to the palette.

Description

Adjusts the colors in a palette according to the adjustment settings of a specified category.

Remarks

An ImageAttributes object maintains color and grayscale settings for five adjustment categories: default, bitmap, brush, pen, and text. For example, you can specify a color-remap table for the default category, a different color-remap table for the bitmap category, and still a different color-remap table for the pen category.

When you call GdipGetImageAttributesAdjustedPalette, you can specify the adjustment category that is used to adjust the palette colors. For example, if you pass ColorAdjustTypeBitmap to the GdipGetImageAttributesAdjustedPalette function, then the adjustment settings of the bitmap category are used to adjust the palette colors.

Example

' ======================================================================================== ' The following example initializes a ColorPalette structure with four colors: aqua, black, ' red, and green. The code also creates an ImageAttributes object and sets its bitmap remap ' table so that green will be converted to blue. Then the code adjusts the palette colors by ' passing the address of the palette to the GdipGetAdjustedPalette function. The code displays ' the four palette colors twice: once before the adjustment and once after the adjustment. ' ======================================================================================== SUB GDIP_GetAdjustedPalette (BYVAL hdc AS HDC)

DIM hStatus AS LONG

' // Create a graphics object from the device context DIM graphics AS GpGraphics PTR hStatus = GdipCreateFromHDC(hdc, @graphics)

' // Get the DPI scaling ratios DIM dpiX AS SINGLE hStatus = GdipGetDpiX(graphics, @dpiX) DIM rxRatio AS SINGLE = dpiX / 96 DIM dpiY AS SINGLE hStatus = GdipGetDpiY(graphics, @dpiY) Dim ryRatio AS SINGLE = dpiY / 96 ' // Set the scale transform hStatus = GdipScaleWorldTransform(graphics, rxRatio, ryRatio, MatrixOrderPrepend)

' // Create a palette that has four entries. DIM clrPalette AS COLORPALETTE PTR DIM PALETTE_SIZE AS LONG = 4 clrPalette = Allocate(SIZEOF(COLORPALETTE) + PALETTE_SIZE * SIZEOF(ARGB)) clrPalette->Flags = 0 clrPalette->Count = PALETTE_SIZE

clrPalette->Entries(0) = ARGB_Aqua clrPalette->Entries(1) = ARGB_Black clrPalette->Entries(2) = ARGB_Red clrPalette->Entries(3) = ARGB_Green

' // Create a SolidBrush DIM brush As GpSolidFill PTR hStatus = GdipCreateSolidFill(ARGB_Black, @brush)

' // Display the four palette colors with no adjustment. FOR j AS LONG = 0 TO PALETTE_SIZE - 1

hStatus = GdipSetSolidFillColor(brush, clrPalette->Entries(j))
  hStatus = GdipFillRectangle (graphics, brush, 30 * j, 0, 20, 20)

NEXT

' // Create a remap table that converts green to blue. DIM map AS GpColorMap map.oldColor = ARGB_Green map.newColor = ARGB_Violet

' // Create an ImageAttributes object, and set its bitmap remap table. DIM imgAttr AS GpImageAttributes PTR hStatus = GdipCreateImageAttributes(@imgAttr) hStatus = GdipSetImageAttributesRemapTable(imgAttr, _

ColorAdjustTypeBitmap, TRUE, 1, @map)

' // Adjust the palette. hStatus = GdipGetImageAttributesAdjustedPalette(imgAttr, clrPalette, ColorAdjustTypeBitmap)

' // Display the four palette colors after the adjustment. FOR j AS LONG = 0 TO PALETTE_SIZE - 1

hStatus = GdipSetSolidFillColor(brush, clrPalette->Entries(j))
  hStatus = GdipFillRectangle (graphics, brush, 30 * j, 30, 20, 20)

NEXT

' // Cleanup IF clrPalette THEN Deallocate(clrPalette) IF imgAttr THEN GdipDisposeImageAttributes(imgAttr) IF brush THEN GdipDeleteBrush(brush) IF graphics THEN GdipDeleteGraphics(graphics)

END SUB ' ========================================================================================

Reference

  • Defined in AfxNova/AfxGdiPlus.bi:2151
  • Documented in Graphics/GdiPlus Flat Api/GdiPlusImageAttributes.md
  • Topic: ImageAttributes Functions