GdipSetImageAttributesColorMatrixfunction
Sets the color-adjustment matrix for a specified category.
Syntax
FUNCTION GdipSetImageAttributesColorMatrix (BYVAL imageattr AS GpImageAttributes PTR, BYVAL type AS ColorAdjustType, BYVAL enableFlag AS BOOL, BYVAL colorMatrix AS ColorMatrix PTR, BYVAL grayMatrix AS ColorMatrix PTR, BYVAL flags AS ColorMatrixFlags) AS GpStatus
Parameters
| Name | Description | |
|---|---|---|
imageattr | [in] Pointer to the ImageAttributes object. | |
type | [in] Element of the ColorAdjustType enumeration that specifies the category for which the color-adjustment matrix is set. The default value is ColorAdjustTypeDefault. | |
enableFlag | [in] Boolean value that specifies whether a separate color adjustment is enabled for the category specified by the type parameter. | |
colorMatrix | [in] Pointer to a 5x5 color-adjustment matrix. | |
grayMatrix | [in] Specifies a matrix to be used for adjusting gray shades when the value of the flags parameter is ColorMatrixFlagsAltGray. | |
flags | [in] Element of the ColorMatrixFlags enumeration that specifies the type of image and color that will be affected by the color-adjustment matrix. |
Description
Sets the color-adjustment matrix for a specified category.
Example
' ======================================================================================== ' This example applies a grayscale color matrix to an image using GdipSetImageAttributesColorMatrix. ' ======================================================================================== SUB Example_SetColorMatrix (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("climber.jpg", @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)
' // Define grayscale color matrix DIM grayMatrix AS ColorMatrix grayMatrix.m(0, 0) = 0.3 : grayMatrix.m(0, 1) = 0.3 : grayMatrix.m(0, 2) = 0.3 : grayMatrix.m(0, 3) = 0 : grayMatrix.m(0, 4) = 0 grayMatrix.m(1, 0) = 0.59: grayMatrix.m(1, 1) = 0.59: grayMatrix.m(1, 2) = 0.59: grayMatrix.m(1, 3) = 0 : grayMatrix.m(1, 4) = 0 grayMatrix.m(2, 0) = 0.11: grayMatrix.m(2, 1) = 0.11: grayMatrix.m(2, 2) = 0.11: grayMatrix.m(2, 3) = 0 : grayMatrix.m(2, 4) = 0 grayMatrix.m(3, 0) = 0 : grayMatrix.m(3, 1) = 0 : grayMatrix.m(3, 2) = 0 : grayMatrix.m(3, 3) = 1 : grayMatrix.m(3, 4) = 0 grayMatrix.m(4, 0) = 0 : grayMatrix.m(4, 1) = 0 : grayMatrix.m(4, 2) = 0 : grayMatrix.m(4, 3) = 0 : grayMatrix.m(4, 4) = 1
' // Apply the color matrix hStatus = GdipSetImageAttributesColorMatrix(imgAttr, ColorAdjustTypeDefault, TRUE, @grayMatrix, NULL, ColorMatrixFlagsDefault)
' // Draw original image hStatus = GdipDrawImageRect(graphics, image, 10, 10, nWidth, nHeight)
' // Draw grayscale image hStatus = GdipDrawImageRectRect(graphics, image, _
200, 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:2132
- Documented in Graphics/GdiPlus Flat Api/GdiPlusImageAttributes.md
- Topic: ImageAttributes Functions