Help Center

GdipSetImageAttributesColorKeysfunction

Sets the color key (transparency range) for a specified category.

Graphicsfunctiondocumented

Syntax

FUNCTION GdipResetImageAttributes (BYVAL imageattr AS GpImageAttributes PTR, BYVAL type AS ColorAdjustType, BYVAL enableFlag AS BOOL, BYVAL colorLow AS ARGB, BYVAL colorHigh AS ARGB) AS GpStatus

Parameters

NameDescription
imageattr[in] Pointer to the ImageAttributes object.
type[in] Element of the ColorAdjustType enumeration that specifies the category for which the color key is set. The default value is ColorAdjustTypeDefault.
enableFlag[in] Boolean value that specifies whether a separate transparency range is enabled for the category specified by the type parameter.
colorLow[in] ARGB color that specifies the low color-key value.
colorHigh[in] ARGB color that specifies the high color-key value.

Description

Sets the color key (transparency range) for a specified category.

Example

' ======================================================================================== ' This example sets a color key to make green pixels transparent, then draws the image ' with and without the transparency effect. ' ======================================================================================== SUB Example_SetColorKeys (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)

' // Load an image from file DIM image AS GpImage PTR hStatus = GdipLoadImageFromFile("RedGreenStripes.bmp", @image) ' // Set the resolution of this image object to the user's DPI settings hStatus = GdipBitmapSetResolution(image, dpiX, dpiY)

' // Get the width and height of the image DIM AS LONG nWidth, nHeight hStatus = GdipGetImageWidth(image, @nWidth) hStatus = GdipGetImageHeight(image, @nHeight)

' // Create an ImageAttributes object DIM imgAttr AS GpImageAttributes PTR hStatus = GdipCreateImageAttributes(@imgAttr)

' // Set color key: make green transparent hStatus = GdipSetImageAttributesColorKeys(imgAttr, ColorAdjustTypeDefault, TRUE, GDIP_ARGB(255,0,128,0), GDIP_ARGB(255,0,255,0))

' // Draw original image (no transparency) hStatus = GdipDrawImageRect(graphics, image, 10, 10, nWidth, nHeight)

' // Draw image with transparency applied hStatus = GdipDrawImageRectRect(graphics, image, _

120, 10, nWidth, nHeight, _
  0, 0, nWidth, nHeight, _
  UnitPixel, imgAttr, NULL, NULL)

' // Cleanup IF imgAttr THEN GdipDisposeImageAttributes(imgAttr) IF image THEN GdipDisposeImage(image) IF graphics THEN GdipDeleteGraphics(graphics)

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

Reference

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