GdipSetImageAttributesToIdentityfunction
Sets the color-adjustment matrix of a specified category to identity matrix.
Syntax
FUNCTION GdipSetImageAttributesToIdentity (BYVAL imageattr AS GpImageAttributes PTR, BYVAL type AS ColorAdjustType) 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 to identity. The default value is ColorAdjustTypeDefault. |
Description
Sets the color-adjustment matrix of a specified category to identity matrix.
Example
' ======================================================================================== ' This example applies a grayscale matrix, then resets it using GdipSetImageAttributesToIdentity. ' ======================================================================================== SUB Example_SetToIdentity (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 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 grayscale matrix hStatus = GdipSetImageAttributesColorMatrix(imgAttr, ColorAdjustTypeDefault, TRUE, @grayMatrix, NULL, ColorMatrixFlagsDefault)
' // Draw grayscale image hStatus = GdipDrawImageRectRect(graphics, image, _
10, 10, nWidth, nHeight, _
0, 0, nWidth, nHeight, _
UnitPixel, imgAttr, NULL, NULL)
' // Reset to identity matrix (remove grayscale) hStatus = GdipSetImageAttributesToIdentity(imgAttr, ColorAdjustTypeDefault)
' // Draw original image (no color adjustment) 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:2130
- Documented in Graphics/GdiPlus Flat Api/GdiPlusImageAttributes.md
- Topic: ImageAttributes Functions