Help Center

GdipSetImageAttributesThresholdfunction

Sets the threshold (transparency range) for a specified category.

Graphicsfunctiondocumented

Syntax

FUNCTION GdipSetImageAttributesThreshold (BYVAL imageattr AS GpImageAttributes PTR, BYVAL type AS ColorAdjustType, BYVAL enableFlag AS BOOL, BYVAL threshold AS REAL) 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 threshold is set. The default value is ColorAdjustTypeDefault.
enableFlag[in] Boolean value that specifies whether a separate threshold is enabled for the category specified by the type parameter.
threshold[in] Single precision value number that specifies the threshold value.

Description

Sets the threshold (transparency range) for a specified category.

Example

' ======================================================================================== ' The following example creates an Image object based on a .bmp file. The code also creates ' an ImageAttributes object and sets its bitmap threshold value to 0.6. Then the code draws ' the image twice: once with no color adjustment and once with the adjustment specified by ' the threshold. ' ======================================================================================== SUB Example_SetThreshold (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 an Image object based on a .bmp file. ' // The image has one stripe with RGB components (160, 0, 0) ' // and one stripe with RGB components (0, 140, 0). DIM image AS GpImage PTR hStatus = GdipLoadImageFromFile("RedGreenThreshold.bmp", @image)

' // Create an ImageAttributes object, and set its bitmap threshold to 0.6. DIM imgAttr AS GpImageAttributes PTR hStatus = GdipCreateImageAttributes(@imgAttr) hStatus = GdipSetImageAttributesThreshold(imgAttr, ColorAdjustTypeBitmap, TRUE, 0.6)

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

' // Draw the image with no color adjustment. hStatus = GdipDrawImageRect(graphics, image, 10, 10, nWidth, nHeight)

' // Draw the image with the threshold applied. ' // 160 > 0.6255, so the red stripe will be changed to full intensity. ' // 140 < 0.6255, so the green stripe will be changed to zero intensity. hStatus = GdipDrawImageRectRect(graphics, image, _

100, 10, nWidth, nHeight, _   ' dest rect
         0, 0, nWidth, nHeight, _      ' source dest
         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:2135
  • Documented in Graphics/GdiPlus Flat Api/GdiPlusImageAttributes.md
  • Topic: ImageAttributes Functions