• Welcome to Jose's Read Only Forum 2023.
 

GDI+: Effects

Started by José Roca, November 04, 2011, 02:12:11 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca

 
The IGdipEffect interface serves as a base interface for eleven interfaces that you can use to apply effects and adjustments to bitmaps. The following interfaces descend from IGdipEffect.

IGdipBlur
IGdipSharpen
IGdipTint
IGdipRedEyeCorrection
IGdipColorMatrixEffect
IGdipColorLUT
IGdipBrightnessContrast
IGdipHueSaturationLightness
IGdipColorBalance
IGdipLevels
IGdipColorCurve

To apply and effect to a bitmap, create an instance of one of the descendants of the IGdipEffect interface, and pass the address of that descendant to the IGdipGraphics.DrawImage method or to the IGdipBitmap.ApplyEffect.


José Roca

 
The following example draws an image twice: once without a blur effect and once with a blur effect. The Matrix object passed to the DrawImage method specifies that the upper-left corner of the blurred image is at (200, 20).


' ########################################################################################
' Microsoft Windows
' File: CGDIP_BlurSetParameters.bas
' Contents: GDI+ example
' This version uses the CWindow and CGdiPlus classes, and the GraphCtx graphic control
' Compilers: PBWIN 10.02+, PBCC 6.02+
' Headers: Windows API headers 2.03+
' Copyright (c) 2011 José Roca. Freeware. Use at your own risk.
' Portions Copyright (c) Microsoft Corporation. All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################

#COMPILE EXE
#DIM ALL
%UNICODE = 1
%USEGRAPHCTX = 1

' // Header files for imported files
#INCLUDE ONCE "CWindow.inc"    ' // CWindow class
#INCLUDE ONCE "CGdiPlus.inc"   ' // CGdiPlus class

%IDC_GRCTX = 1001

' ========================================================================================
' The following example draws an image twice: once without a blur effect and once with a
' blur effect. The Matrix object passed to the DrawImage method specifies that the
' upper-left corner of the blurred image is at (200, 20).
' ========================================================================================
SUB Example_BlurSetParameters (BYVAL pGdip AS IGdiPlus, BYVAL hdc AS DWORD)

'   Graphics graphics(hdc);
   LOCAL graphics AS IGdipGraphics
   graphics = pGdip.Graphics(hdc)

'   Image myImage(L"Picture.bmp");
   LOCAL myImage AS IGdipImage
   myImage = pGdip.Image("climber.jpg")

'   REAL srcWidth = (REAL)myImage.GetWidth();
'   REAL srcHeight = (REAL)myImage.GetHeight();
   LOCAL srcWidth AS SINGLE
   srcWidth = myImage.GetWidth
   LOCAL srcHeight AS SINGLE
   srcHeight = myImage.GetHeight

'   RectF srcRect(0.0f, 0.0f, srcWidth, srcHeight);
   LOCAL srcRect AS RectF
   srcRect = pGdip.RectF(0, 0, srcWidth, srcHeight)

'   Matrix myMatrix(1.0f, 0.0f, 0.0f, 1.0f, 200.0f, 20.0f);
   LOCAL myMatrix AS IGdipMatrix
   myMatrix = pGdip.Matrix
   myMatrix.Matrix2(1, 0, 0, 1, 200, 20)

'   BlurParams myBlurParams;
'   myBlurParams.expandEdge = TRUE;
'   myBlurParams.radius = 3;
   LOCAL myBlurParams AS BlurParams
   myBlurParams.expandEdge = %TRUE
   myBlurParams.radius = 3

'   Blur myBlur;
'   myBlur.SetParameters(&myBlurParams);
   LOCAL myBlur AS IGdipBlur
   myBlur = pGdip.Blur
   myBlur.SetParameters(myBlurParams)

'   // Draw the image without the blur effect.
'   graphics.DrawImage(&myImage, 20.0, 20.0, srcWidth, srcHeight);
   graphics.DrawImageRect(myImage, 20, 20, srcWidth, srcHeight)

'   // Draw the image with the blur effect.
'   graphics.DrawImage(&myImage, &srcRect, &myMatrix, &myBlur, NULL, UnitPixel);
   graphics.DrawImageFx(myImage, srcRect, myMatrix, myBlur, NOTHING, %UnitPixel)

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

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG

   ' // Create an instance of the CWindow class
   LOCAL pWindow AS IWindow
   pWindow = CLASS "CWindow"
   IF ISNOTHING(pWindow) THEN EXIT FUNCTION

   ' // Create the main window
   LOCAL hwnd AS DWORD
   hwnd = pWindow.CreateWindow(%NULL, "BlurSetParameters", 0, 0, 0, 0, 0, 0, CODEPTR(WindowProc))
   pWindow.SetClientSize 400, 250
   ' // Center the window
   pWindow.CenterWindow

   ' // Create an instance of the GdiPlus class
   LOCAL pGdip AS IGdiPlus
   pGdip = NewGdiPlus

   ' // Add a GDI+ aware graphic control
   LOCAL hCtrl AS DWORD
   hCtrl = pWindow.AddGraphCtx(hwnd, %IDC_GRCTX, "", 0, 0, pWindow.ClientWidth, pWindow.ClientHeight)
   GraphCtx_Clear(hCtrl, %WHITE)

   ' // Get the memory device context of the graphic control
   LOCAL hdc AS DWORD
   hdc = GraphCtx_GetDc(hCtrl)

   ' // Draw the graphics
   Example_BlurSetParameters(pGdip, hdc)

   ' // Default message pump (you can replace it with your own)
   pWindow.DoEvents(nCmdShow)

END FUNCTION
' ========================================================================================

' ========================================================================================
' Main callback function.
' ========================================================================================
FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG

   SELECT CASE uMsg

      CASE %WM_COMMAND
         SELECT CASE LO(WORD, wParam)
            CASE %IDCANCEL
               ' // If the Escape key has been pressed...
               IF HI(WORD, wParam) = %BN_CLICKED THEN
                  ' // ... close the application by sending a WM_CLOSE message
                  SendMessage hwnd, %WM_CLOSE, 0, 0
               END IF
         END SELECT

      CASE %WM_DESTROY
         ' // End the application
         PostQuitMessage 0
         EXIT FUNCTION

   END SELECT

   ' // Pass unprocessed messages to Windows
   FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)

END FUNCTION
' ========================================================================================


José Roca

 
The following example draws an image twice: once with no change in contrast and once with increased contrast. The brightness level of the image is not changed. The Matrix object passed to the DrawImage method specifies that the upper-left corner of the adjusted image is at (200, 20).


' ########################################################################################
' Microsoft Windows
' File: CGDIP_BrightnessContrastSetParameters.bas
' Contents: GDI+ example
' This version uses the CWindow and CGdiPlus classes, and the GraphCtx graphic control
' Compilers: PBWIN 10.02+, PBCC 6.02+
' Headers: Windows API headers 2.03+
' Copyright (c) 2011 José Roca. Freeware. Use at your own risk.
' Portions Copyright (c) Microsoft Corporation. All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################

#COMPILE EXE
#DIM ALL
%UNICODE = 1
%USEGRAPHCTX = 1

' // Header files for imported files
#INCLUDE ONCE "CWindow.inc"    ' // CWindow class
#INCLUDE ONCE "CGdiPlus.inc"   ' // CGdiPlus class

%IDC_GRCTX = 1001

' ========================================================================================
' The following example draws an image twice: once with no change in contrast and once with
' increased contrast. The brightness level of the image is not changed. The Matrix object
' passed to the DrawImage method specifies that the upper-left corner of the adjusted image
' is at (200, 20).
' ========================================================================================
SUB Example_BrightnessContrastSetParameters (BYVAL pGdip AS IGdiPlus, BYVAL hdc AS DWORD)

'   Graphics graphics(hdc);
   LOCAL graphics AS IGdipGraphics
   graphics = pGdip.Graphics(hdc)

'   Image myImage(L"Picture.bmp");
   LOCAL myImage AS IGdipImage
   myImage = pGdip.Image("climber.jpg")

'   REAL srcWidth = (REAL)myImage.GetWidth();
'   REAL srcHeight = (REAL)myImage.GetHeight();
   LOCAL srcWidth AS SINGLE
   srcWidth = myImage.GetWidth
   LOCAL srcHeight AS SINGLE
   srcHeight = myImage.GetHeight

'   RectF srcRect(0.0f, 0.0f, srcWidth, srcHeight);
   LOCAL srcRect AS RectF
   srcRect = pGdip.RectF(0, 0, srcWidth, srcHeight)

'   Matrix myMatrix(1.0f, 0.0f, 0.0f, 1.0f, 200.0f, 20.0f);
   LOCAL myMatrix AS IGdipMatrix
   myMatrix = pGdip.Matrix
   myMatrix.Matrix2(1, 0, 0, 1, 200, 20)

'   BrightnessContrastParams briConParams;
'   briConParams.brightnessLevel = 0;
'   briConParams.contrastLevel = 25;
   LOCAL briConParams AS BrightnessContrastParams
   briConParams.brightnessLevel = 0
   briConParams.contrastLevel = 25

'   BrightnessContrast briCon;
'   briCon.SetParameters(&briConParams);
   LOCAL briCon AS IGdipBrightnessContrast
   briCon = pGdip.BrightnessContrast
   briCon.SetParameters(briConParams)

'   // Draw the image without the blur effect.
'   graphics.DrawImage(&myImage, 20.0, 20.0, srcWidth, srcHeight);
   graphics.DrawImageRect(myImage, 20, 20, srcWidth, srcHeight)

'   // Draw the image with the increased effect.
'   graphics.DrawImage(&myImage, &srcRect, &myMatrix, &briCon, NULL, UnitPixel);
   graphics.DrawImageFx(myImage, srcRect, myMatrix, briCon, NOTHING, %UnitPixel)

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

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG

   ' // Create an instance of the CWindow class
   LOCAL pWindow AS IWindow
   pWindow = CLASS "CWindow"
   IF ISNOTHING(pWindow) THEN EXIT FUNCTION

   ' // Create the main window
   LOCAL hwnd AS DWORD
   hwnd = pWindow.CreateWindow(%NULL, "BrightnessContrastSetParameters", 0, 0, 0, 0, 0, 0, CODEPTR(WindowProc))
   pWindow.SetClientSize 400, 250
   ' // Center the window
   pWindow.CenterWindow

   ' // Create an instance of the GdiPlus class
   LOCAL pGdip AS IGdiPlus
   pGdip = NewGdiPlus

   ' // Add a GDI+ aware graphic control
   LOCAL hCtrl AS DWORD
   hCtrl = pWindow.AddGraphCtx(hwnd, %IDC_GRCTX, "", 0, 0, pWindow.ClientWidth, pWindow.ClientHeight)
   GraphCtx_Clear(hCtrl, %WHITE)

   ' // Get the memory device context of the graphic control
   LOCAL hdc AS DWORD
   hdc = GraphCtx_GetDc(hCtrl)

   ' // Draw the graphics
   Example_BrightnessContrastSetParameters(pGdip, hdc)

   ' // Default message pump (you can replace it with your own)
   pWindow.DoEvents(nCmdShow)

END FUNCTION
' ========================================================================================

' ========================================================================================
' Main callback function.
' ========================================================================================
FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG

   SELECT CASE uMsg

      CASE %WM_COMMAND
         SELECT CASE LO(WORD, wParam)
            CASE %IDCANCEL
               ' // If the Escape key has been pressed...
               IF HI(WORD, wParam) = %BN_CLICKED THEN
                  ' // ... close the application by sending a WM_CLOSE message
                  SendMessage hwnd, %WM_CLOSE, 0, 0
               END IF
         END SELECT

      CASE %WM_DESTROY
         ' // End the application
         PostQuitMessage 0
         EXIT FUNCTION

   END SELECT

   ' // Pass unprocessed messages to Windows
   FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)

END FUNCTION
' ========================================================================================


José Roca

 
The following example draws an image twice, once with no change and once with the red increased (cyan decreased). The Matrix object passed to the DrawImage method specifies that the upper-left corner of the altered image is at (200, 20).


' ########################################################################################
' Microsoft Windows
' File: CGDIP_ColorBalanceSetParameters.bas
' Contents: GDI+ example
' This version uses the CWindow and CGdiPlus classes, and the GraphCtx graphic control
' Compilers: PBWIN 10.02+, PBCC 6.02+
' Headers: Windows API headers 2.03+
' Copyright (c) 2011 José Roca. Freeware. Use at your own risk.
' Portions Copyright (c) Microsoft Corporation. All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################

#COMPILE EXE
#DIM ALL
%UNICODE = 1
%USEGRAPHCTX = 1

' // Header files for imported files
#INCLUDE ONCE "CWindow.inc"    ' // CWindow class
#INCLUDE ONCE "CGdiPlus.inc"   ' // CGdiPlus class

%IDC_GRCTX = 1001

' ========================================================================================
' The following example draws an image twice, once with no change and once with the red
' increased (cyan decreased). The Matrix object passed to the DrawImage method specifies
' that the upper-left corner of the altered image is at (200, 20).
' ========================================================================================
SUB Example_ColorBalanceSetParameters (BYVAL pGdip AS IGdiPlus, BYVAL hdc AS DWORD)

'   Graphics graphics(hdc);
   LOCAL graphics AS IGdipGraphics
   graphics = pGdip.Graphics(hdc)

'   Image myImage(L"Picture.bmp");
   LOCAL myImage AS IGdipImage
   myImage = pGdip.Image("climber.jpg")

'   REAL srcWidth = (REAL)myImage.GetWidth();
'   REAL srcHeight = (REAL)myImage.GetHeight();
   LOCAL srcWidth AS SINGLE
   srcWidth = myImage.GetWidth
   LOCAL srcHeight AS SINGLE
   srcHeight = myImage.GetHeight

'   RectF srcRect(0.0f, 0.0f, srcWidth, srcHeight);
   LOCAL srcRect AS RectF
   srcRect = pGdip.RectF(0, 0, srcWidth, srcHeight)

'   Matrix myMatrix(1.0f, 0.0f, 0.0f, 1.0f, 200.0f, 20.0f);
   LOCAL myMatrix AS IGdipMatrix
   myMatrix = pGdip.Matrix
   myMatrix.Matrix2(1, 0, 0, 1, 200, 20)

'   ColorBalanceParams colBalParams;
'   colBalParams.cyanRed = 10;
'   colBalParams.magentaGreen = 0;
'   colBalParams.yellowBlue = 0;
   LOCAL colBalParams AS ColorBalanceParams
   colBalParams.cyanRed = 10
   colBalParams.magentaGreen = 0
   colBalParams.yellowBlue = 0

'   ColorBalance colBal;
'   colBal.SetParameters(&colBalParams);
   LOCAL colBal AS IGdipColorBalance
   colBal = pGdip.ColorBalance
   colBal.SetParameters(colBalParams)

'   // Draw the image without the blur effect.
'   graphics.DrawImage(&myImage, 20.0, 20.0, srcWidth, srcHeight);
   graphics.DrawImageRect(myImage, 20, 20, srcWidth, srcHeight)

'   // Draw the image with the increased effect.
'   graphics.DrawImage(&myImage, &srcRect, &myMatrix, &colBal, NULL, UnitPixel);
   graphics.DrawImageFx(myImage, srcRect, myMatrix, colBal, NOTHING, %UnitPixel)

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

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG

   ' // Create an instance of the CWindow class
   LOCAL pWindow AS IWindow
   pWindow = CLASS "CWindow"
   IF ISNOTHING(pWindow) THEN EXIT FUNCTION

   ' // Create the main window
   LOCAL hwnd AS DWORD
   hwnd = pWindow.CreateWindow(%NULL, "ColorBalanceSetParameters", 0, 0, 0, 0, 0, 0, CODEPTR(WindowProc))
   pWindow.SetClientSize 400, 250
   ' // Center the window
   pWindow.CenterWindow

   ' // Create an instance of the GdiPlus class
   LOCAL pGdip AS IGdiPlus
   pGdip = NewGdiPlus

   ' // Add a GDI+ aware graphic control
   LOCAL hCtrl AS DWORD
   hCtrl = pWindow.AddGraphCtx(hwnd, %IDC_GRCTX, "", 0, 0, pWindow.ClientWidth, pWindow.ClientHeight)
   GraphCtx_Clear(hCtrl, %WHITE)

   ' // Get the memory device context of the graphic control
   LOCAL hdc AS DWORD
   hdc = GraphCtx_GetDc(hCtrl)

   ' // Draw the graphics
   Example_ColorBalanceSetParameters(pGdip, hdc)

   ' // Default message pump (you can replace it with your own)
   pWindow.DoEvents(nCmdShow)

END FUNCTION
' ========================================================================================

' ========================================================================================
' Main callback function.
' ========================================================================================
FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG

   SELECT CASE uMsg

      CASE %WM_COMMAND
         SELECT CASE LO(WORD, wParam)
            CASE %IDCANCEL
               ' // If the Escape key has been pressed...
               IF HI(WORD, wParam) = %BN_CLICKED THEN
                  ' // ... close the application by sending a WM_CLOSE message
                  SendMessage hwnd, %WM_CLOSE, 0, 0
               END IF
         END SELECT

      CASE %WM_DESTROY
         ' // End the application
         PostQuitMessage 0
         EXIT FUNCTION

   END SELECT

   ' // Pass unprocessed messages to Windows
   FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)

END FUNCTION
' ========================================================================================


José Roca

 
The following example draws an image twice, once with no adjustment and once with a shadow adjustment. The Matrix object passed to the DrawImage method specifies that the upper-left corner of the adjusted image is at (200, 20).


' ########################################################################################
' Microsoft Windows
' File: CGDIP_ColorCurveSetParameters.bas
' Contents: GDI+ example
' This version uses the CWindow and CGdiPlus classes, and the GraphCtx graphic control
' Compilers: PBWIN 10+, PBCC 6+
' Compilers: PBWIN 10.02+, PBCC 6.02+
' Copyright (c) 2011 José Roca. Freeware. Use at your own risk.
' Portions Copyright (c) Microsoft Corporation. All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################

#COMPILE EXE
#DIM ALL
%UNICODE = 1
%USEGRAPHCTX = 1

' // Header files for imported files
#INCLUDE ONCE "CWindow.inc"    ' // CWindow class
#INCLUDE ONCE "CGdiPlus.inc"   ' // CGdiPlus class

%IDC_GRCTX = 1001

' ========================================================================================
' The following example draws an image twice, once with no adjustment and once with a
' shadow adjustment. The Matrix object passed to the DrawImage method specifies that the
' upper-left corner of the adjusted image is at (200, 20).
' ========================================================================================
SUB Example_ColorCurveSetParameters (BYVAL pGdip AS IGdiPlus, BYVAL hdc AS DWORD)

'   Graphics graphics(hdc);
   LOCAL graphics AS IGdipGraphics
   graphics = pGdip.Graphics(hdc)

'   Image myImage(L"Picture.bmp");
   LOCAL myImage AS IGdipImage
   myImage = pGdip.Image("climber.jpg")

'   REAL srcWidth = (REAL)myImage.GetWidth();
'   REAL srcHeight = (REAL)myImage.GetHeight();
   LOCAL srcWidth AS SINGLE
   srcWidth = myImage.GetWidth
   LOCAL srcHeight AS SINGLE
   srcHeight = myImage.GetHeight

'   RectF srcRect(0.0f, 0.0f, srcWidth, srcHeight);
   LOCAL srcRect AS RectF
   srcRect = pGdip.RectF(0, 0, srcWidth, srcHeight)

'   Matrix myMatrix(1.0f, 0.0f, 0.0f, 1.0f, 200.0f, 20.0f);
   LOCAL myMatrix AS IGdipMatrix
   myMatrix = pGdip.Matrix
   myMatrix.Matrix2(1, 0, 0, 1, 200, 20)

'   ColorCurveParams colCurParams;
'   colCurParams.adjustment = AdjustShadow;
'   colCurParams.channel = CurveChannelAll;
'   colCurParams.adjustValue = 50;
   LOCAL colCurParams AS ColorCurveParams
   colCurParams.adjustment = %AdjustShadow
   colCurParams.channel = %CurveChannelAll
   colCurParams.adjustValue = 50

'   ColorCurve colCur;
'   colCur.SetParameters(&colCurParams);
   LOCAL colCur AS IGdipColorBalance
   colCur = pGdip.ColorBalance
   colCur.SetParameters(colCurParams)

'   // Draw the image with no change.
'   graphics.DrawImage(&myImage, 20.0, 20.0, srcWidth, srcHeight);
   graphics.DrawImageRect(myImage, 20, 20, srcWidth, srcHeight)

'   // Draw the image with increased definition in the dark areas.
'   graphics.DrawImage(&myImage, &srcRect, &myMatrix, &colCur, NULL, UnitPixel);
   graphics.DrawImageFx(myImage, srcRect, myMatrix, colCur, NOTHING, %UnitPixel)

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

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG

   ' // Create an instance of the CWindow class
   LOCAL pWindow AS IWindow
   pWindow = CLASS "CWindow"
   IF ISNOTHING(pWindow) THEN EXIT FUNCTION

   ' // Create the main window
   LOCAL hwnd AS DWORD
   hwnd = pWindow.CreateWindow(%NULL, "ColorCurveSetParameters", 0, 0, 0, 0, 0, 0, CODEPTR(WindowProc))
   pWindow.SetClientSize 400, 250
   ' // Center the window
   pWindow.CenterWindow

   ' // Create an instance of the GdiPlus class
   LOCAL pGdip AS IGdiPlus
   pGdip = NewGdiPlus

   ' // Add a GDI+ aware graphic control
   LOCAL hCtrl AS DWORD
   hCtrl = pWindow.AddGraphCtx(hwnd, %IDC_GRCTX, "", 0, 0, pWindow.ClientWidth, pWindow.ClientHeight)
   GraphCtx_Clear(hCtrl, %WHITE)

   ' // Get the memory device context of the graphic control
   LOCAL hdc AS DWORD
   hdc = GraphCtx_GetDc(hCtrl)

   ' // Draw the graphics
   Example_ColorCurveSetParameters(pGdip, hdc)

   ' // Default message pump (you can replace it with your own)
   pWindow.DoEvents(nCmdShow)

END FUNCTION
' ========================================================================================

' ========================================================================================
' Main callback function.
' ========================================================================================
FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG

   SELECT CASE uMsg

      CASE %WM_COMMAND
         SELECT CASE LO(WORD, wParam)
            CASE %IDCANCEL
               ' // If the Escape key has been pressed...
               IF HI(WORD, wParam) = %BN_CLICKED THEN
                  ' // ... close the application by sending a WM_CLOSE message
                  SendMessage hwnd, %WM_CLOSE, 0, 0
               END IF
         END SELECT

      CASE %WM_DESTROY
         ' // End the application
         PostQuitMessage 0
         EXIT FUNCTION

   END SELECT

   ' // Pass unprocessed messages to Windows
   FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)

END FUNCTION
' ========================================================================================


José Roca

 
The following example draws and image twice, once with no adjustment and once with a custom adjustment specified by four lookup tables. The alpha lookup table replaces all alpha values with 255 so the resulting bitmap will be opaque. The red, green, and blue lookup tables are all the same; each is a power function (with an exponent of 0.5) that passes through (0, 0) and (255, 255). The Matrix object passed to the DrawImage method specifies that the upper-left corner of the adjusted image is at (200, 20).


' ########################################################################################
' Microsoft Windows
' File: CGDIP_ColorLUTSetParameters.bas
' Contents: GDI+ example
' This version uses the CWindow and CGdiPlus classes, and the GraphCtx graphic control
' Compilers: PBWIN 10.02+, PBCC 6.02+
' Headers: Windows API headers 2.03+
' Copyright (c) 2011 José Roca. Freeware. Use at your own risk.
' Portions Copyright (c) Microsoft Corporation. All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################

#COMPILE EXE
#DIM ALL
%UNICODE = 1
%USEGRAPHCTX = 1

' // Header files for imported files
#INCLUDE ONCE "CWindow.inc"    ' // CWindow class
#INCLUDE ONCE "CGdiPlus.inc"   ' // CGdiPlus class

%IDC_GRCTX = 1001

' ========================================================================================
' The following example draws and image twice, once with no adjustment and once with a
' custom adjustment specified by four lookup tables. The alpha lookup table replaces all
' alpha values with 255 so the resulting bitmap will be opaque. The red, green, and blue
' lookup tables are all the same; each is a power function (with an exponent of 0.5) that
' passes through (0, 0) and (255, 255). The Matrix object passed to the DrawImage method
' specifies that the upper-left corner of the adjusted image is at (200, 20).
' ========================================================================================
SUB Example_ColorLUTSetParameters (BYVAL pGdip AS IGdiPlus, BYVAL hdc AS DWORD)

'   Graphics graphics(hdc);
   LOCAL graphics AS IGdipGraphics
   graphics = pGdip.Graphics(hdc)

'   Image myImage(L"Picture.bmp");
   LOCAL myImage AS IGdipImage
   myImage = pGdip.Image("climber.jpg")

'   REAL srcWidth = (REAL)myImage.GetWidth();
'   REAL srcHeight = (REAL)myImage.GetHeight();
   LOCAL srcWidth AS SINGLE
   srcWidth = myImage.GetWidth
   LOCAL srcHeight AS SINGLE
   srcHeight = myImage.GetHeight

'   RectF srcRect(0.0f, 0.0f, srcWidth, srcHeight);
   LOCAL srcRect AS RectF
   srcRect = pGdip.RectF(0, 0, srcWidth, srcHeight)

'   Matrix myMatrix(1.0f, 0.0f, 0.0f, 1.0f, 200.0f, 20.0f);
   LOCAL myMatrix AS IGdipMatrix
   myMatrix = pGdip.Matrix
   myMatrix.Matrix2(1, 0, 0, 1, 200, 20)

'   ColorLUTParams myColLUTParams;
   LOCAL myColLUTParams AS ColorLUTParams

'   for(INT j = 0; j < 256; ++j)
'   {
'      myColLUTParams.lutA[j] = 255;
'      myColLUTParams.lutR[j] = (BYTE)(255.0*pow(j/255.0, 0.5));
'      myColLUTParams.lutG[j] = (BYTE)(255.0*pow(j/255.0, 0.5));
'      myColLUTParams.lutB[j] = (BYTE)(255.0*pow(j/255.0, 0.5));
'   }

   LOCAL j AS LONG
   FOR j = 0 TO 255
      myColLUTParams.lutA(j) = 255
      myColLUTParams.lutR(j) = 255.0! * ((j/255.0!) ^ 0.5!)
      myColLUTParams.lutG(j) = 255.0! * ((j/255.0!) ^ 0.5!)
      myColLUTParams.lutB(j) = 255.0! * ((j/255.0!) ^ 0.5!)
   NEXT

'   ColorLUT myColLUT;
'   myColLUT.SetParameters(&myColLUTParams);
   LOCAL myColLUT AS IGdipColorLUT
   myColLUT = pGdip.ColorLUT
   myColLUT.SetParameters(myColLUTParams)

'   // Draw the image with no change.
'   graphics.DrawImage(&myImage, 20.0, 20.0, srcWidth, srcHeight);
   graphics.DrawImageRect(myImage, 20, 20, srcWidth, srcHeight)

'   // Draw the transformed image.
'   graphics.DrawImage(&myImage, &srcRect, &myMatrix, &myColLUT, NULL, UnitPixel);
   graphics.DrawImageFx(myImage, srcRect, myMatrix, myColLUT, NOTHING, %UnitPixel)

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

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG

   ' // Create an instance of the CWindow class
   LOCAL pWindow AS IWindow
   pWindow = CLASS "CWindow"
   IF ISNOTHING(pWindow) THEN EXIT FUNCTION

   ' // Create the main window
   LOCAL hwnd AS DWORD
   hwnd = pWindow.CreateWindow(%NULL, "ColorLUTSetParameters", 0, 0, 0, 0, 0, 0, CODEPTR(WindowProc))
   pWindow.SetClientSize 400, 250
   ' // Center the window
   pWindow.CenterWindow

   ' // Create an instance of the GdiPlus class
   LOCAL pGdip AS IGdiPlus
   pGdip = NewGdiPlus

   ' // Add a GDI+ aware graphic control
   LOCAL hCtrl AS DWORD
   hCtrl = pWindow.AddGraphCtx(hwnd, %IDC_GRCTX, "", 0, 0, pWindow.ClientWidth, pWindow.ClientHeight)
   GraphCtx_Clear(hCtrl, %WHITE)

   ' // Get the memory device context of the graphic control
   LOCAL hdc AS DWORD
   hdc = GraphCtx_GetDc(hCtrl)

   ' // Draw the graphics
   Example_ColorLUTSetParameters(pGdip, hdc)

   ' // Default message pump (you can replace it with your own)
   pWindow.DoEvents(nCmdShow)

END FUNCTION
' ========================================================================================

' ========================================================================================
' Main callback function.
' ========================================================================================
FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG

   SELECT CASE uMsg

      CASE %WM_COMMAND
         SELECT CASE LO(WORD, wParam)
            CASE %IDCANCEL
               ' // If the Escape key has been pressed...
               IF HI(WORD, wParam) = %BN_CLICKED THEN
                  ' // ... close the application by sending a WM_CLOSE message
                  SendMessage hwnd, %WM_CLOSE, 0, 0
               END IF
         END SELECT

      CASE %WM_DESTROY
         ' // End the application
         PostQuitMessage 0
         EXIT FUNCTION

   END SELECT

   ' // Pass unprocessed messages to Windows
   FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)

END FUNCTION
' ========================================================================================


José Roca

 
The following example draws an image twice: once with no change and once with a transformation specified by a color matrix. The transformation increases all red channel values by 20 percent and increases all green channel values by 30 percent. The Matrix object (not a color matrix) passed to the DrawImage method specifies that the upper-left corner of the altered image is at (200, 20).


' ########################################################################################
' Microsoft Windows
' File: CGDIP_ColorMatrixEffectSetParameters.bas
' Contents: GDI+ example
' This version uses the CWindow and CGdiPlus classes, and the GraphCtx graphic control
' Compilers: PBWIN 10.02+, PBCC 6.02+
' Headers: Windows API headers 2.03+
' Copyright (c) 2011 José Roca. Freeware. Use at your own risk.
' Portions Copyright (c) Microsoft Corporation. All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################

#COMPILE EXE
#DIM ALL
%UNICODE = 1
%USEGRAPHCTX = 1

' // Header files for imported files
#INCLUDE ONCE "CWindow.inc"    ' // CWindow class
#INCLUDE ONCE "CGdiPlus.inc"   ' // CGdiPlus class

%IDC_GRCTX = 1001

' ========================================================================================
' The following example draws an image twice: once with no change and once with a
' transformation specified by a color matrix. The transformation increases all red channel
' values by 20 percent and increases all green channel values by 30 percent. The Matrix
' object (not a color matrix) passed to the DrawImage method specifies that the upper-left
' corner of the altered image is at (200, 20).
' ========================================================================================
SUB Example_ColorMatrixEffectSetParameters (BYVAL pGdip AS IGdiPlus, BYVAL hdc AS DWORD)

'   Graphics graphics(hdc);
   LOCAL graphics AS IGdipGraphics
   graphics = pGdip.Graphics(hdc)

'   Image myImage(L"Picture.bmp");
   LOCAL myImage AS IGdipImage
   myImage = pGdip.Image("climber.jpg")

'   REAL srcWidth = (REAL)myImage.GetWidth();
'   REAL srcHeight = (REAL)myImage.GetHeight();
   LOCAL srcWidth AS SINGLE
   srcWidth = myImage.GetWidth
   LOCAL srcHeight AS SINGLE
   srcHeight = myImage.GetHeight

'   RectF srcRect(0.0f, 0.0f, srcWidth, srcHeight);
   LOCAL srcRect AS RectF
   srcRect = pGdip.RectF(0, 0, srcWidth, srcHeight)

'   ColorMatrix myColMat = {
'      1.2f, 0.0f, 0.0f, 0.0f, 0.0f,
'      0.0f, 1.3f, 0.0f, 0.0f, 0.0f,
'      0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
'      0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
'      0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
   LOCAL myColMat AS ColorMatrix
   myColMat.m(0, 0) = 1.2! : myColMat.m(0, 1) = 0.0! : myColMat.m(0, 2) = 0.0! : myColMat.m(0, 3) = 0.0! :  myColMat.m(0, 4) = 0.0!
   myColMat.m(1, 0) = 0.0! : myColMat.m(1, 1) = 1.3! : myColMat.m(1, 2) = 0.0! : myColMat.m(1, 3) = 0.0! :  myColMat.m(1, 4) = 0.0!
   myColMat.m(2, 0) = 0.0! : myColMat.m(2, 1) = 0.0! : myColMat.m(2, 2) = 1.0! : myColMat.m(2, 3) = 0.0! :  myColMat.m(2, 4) = 0.0!
   myColMat.m(3, 0) = 0.0! : myColMat.m(3, 1) = 0.0! : myColMat.m(3, 2) = 0.0! : myColMat.m(3, 3) = 1.0! :  myColMat.m(3, 4) = 0.0!
   myColMat.m(4, 0) = 0.0! : myColMat.m(3, 1) = 0.0! : myColMat.m(3, 2) = 0.0! : myColMat.m(3, 3) = 0.0! :  myColMat.m(3, 4) = 1.0!

'   Matrix myMatrix(1.0f, 0.0f, 0.0f, 1.0f, 200.0f, 20.0f);
   LOCAL myMatrix AS IGdipMatrix
   myMatrix = pGdip.Matrix
   myMatrix.Matrix2(1, 0, 0, 1, 200, 20)

'   ColorMatrixEffect myColMatEff;
'   myColMatEff.SetParameters(&myColMat);
   LOCAL myColMatEff AS IGdipColorMatrixEffect
   myColMatEff = pGdip.ColorMatrixEffect
   myColMatEff.SetParameters(myColMat)

'   // Draw the image with no change.
'   graphics.DrawImage(&myImage, 20.0, 20.0, srcWidth, srcHeight);
   graphics.DrawImageRect(myImage, 20, 20, srcWidth, srcHeight)

'   // Draw the transformed image.
'   graphics.DrawImage(&myImage, &srcRect, &myMatrix, &myColMatEff, NULL, UnitPixel);
   graphics.DrawImageFx(myImage, srcRect, myMatrix, myColMatEff, NOTHING, %UnitPixel)

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

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG

   ' // Create an instance of the CWindow class
   LOCAL pWindow AS IWindow
   pWindow = CLASS "CWindow"
   IF ISNOTHING(pWindow) THEN EXIT FUNCTION

   ' // Create the main window
   LOCAL hwnd AS DWORD
   hwnd = pWindow.CreateWindow(%NULL, "ColorMatrixEffectSetParameters", 0, 0, 0, 0, 0, 0, CODEPTR(WindowProc))
   pWindow.SetClientSize 400, 250
   ' // Center the window
   pWindow.CenterWindow

   ' // Create an instance of the GdiPlus class
   LOCAL pGdip AS IGdiPlus
   pGdip = NewGdiPlus

   ' // Add a GDI+ aware graphic control
   LOCAL hCtrl AS DWORD
   hCtrl = pWindow.AddGraphCtx(hwnd, %IDC_GRCTX, "", 0, 0, pWindow.ClientWidth, pWindow.ClientHeight)
   GraphCtx_Clear(hCtrl, %WHITE)

   ' // Get the memory device context of the graphic control
   LOCAL hdc AS DWORD
   hdc = GraphCtx_GetDc(hCtrl)

   ' // Draw the graphics
   Example_ColorMatrixEffectSetParameters(pGdip, hdc)

   ' // Default message pump (you can replace it with your own)
   pWindow.DoEvents(nCmdShow)

END FUNCTION
' ========================================================================================

' ========================================================================================
' Main callback function.
' ========================================================================================
FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG

   SELECT CASE uMsg

      CASE %WM_COMMAND
         SELECT CASE LO(WORD, wParam)
            CASE %IDCANCEL
               ' // If the Escape key has been pressed...
               IF HI(WORD, wParam) = %BN_CLICKED THEN
                  ' // ... close the application by sending a WM_CLOSE message
                  SendMessage hwnd, %WM_CLOSE, 0, 0
               END IF
         END SELECT

      CASE %WM_DESTROY
         ' // End the application
         PostQuitMessage 0
         EXIT FUNCTION

   END SELECT

   ' // Pass unprocessed messages to Windows
   FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)

END FUNCTION
' ========================================================================================


José Roca

 
The following example draws an image twice: once with no change and once with increased saturation. The Matrix object passed to the DrawImage method specifies that the upper-left corner of the adjusted image is at (200, 20).


' ########################################################################################
' Microsoft Windows
' File: CGDIP_HueSaturationLightnessSetParameters.bas
' Contents: GDI+ example
' This version uses the CWindow and CGdiPlus classes, and the GraphCtx graphic control
' Compilers: PBWIN 10.02+, PBCC 6.02+
' Headers: Windows API headers 2.03+
' Copyright (c) 2011 José Roca. Freeware. Use at your own risk.
' Portions Copyright (c) Microsoft Corporation. All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################

#COMPILE EXE
#DIM ALL
%UNICODE = 1
%USEGRAPHCTX = 1

' // Header files for imported files
#INCLUDE ONCE "CWindow.inc"    ' // CWindow class
#INCLUDE ONCE "CGdiPlus.inc"   ' // CGdiPlus class

%IDC_GRCTX = 1001

' ========================================================================================
' The following example draws an image twice: once with no change and once with increased
' saturation. The Matrix object passed to the DrawImage method specifies that the upper-left
' corner of the adjusted image is at (200, 20).
' ========================================================================================
SUB Example_HSLSetParameters (BYVAL pGdip AS IGdiPlus, BYVAL hdc AS DWORD)

'   Graphics graphics(hdc);
   LOCAL graphics AS IGdipGraphics
   graphics = pGdip.Graphics(hdc)

'   Image myImage(L"Picture.bmp");
   LOCAL myImage AS IGdipImage
   myImage = pGdip.Image("climber.jpg")

'   REAL srcWidth = (REAL)myImage.GetWidth();
'   REAL srcHeight = (REAL)myImage.GetHeight();
   LOCAL srcWidth AS SINGLE
   srcWidth = myImage.GetWidth
   LOCAL srcHeight AS SINGLE
   srcHeight = myImage.GetHeight

'   RectF srcRect(0.0f, 0.0f, srcWidth, srcHeight);
   LOCAL srcRect AS RectF
   srcRect = pGdip.RectF(0, 0, srcWidth, srcHeight)

'   Matrix myMatrix(1.0f, 0.0f, 0.0f, 1.0f, 200.0f, 20.0f);
   LOCAL myMatrix AS IGdipMatrix
   myMatrix = pGdip.Matrix
   myMatrix.Matrix2(1, 0, 0, 1, 200, 20)

'   HueSaturationLightnessParams myHSLParams;
'   myHSLParams.hueLevel = 0;
'   myHSLParams.lightnessLevel = 0;
'   myHSLParams.saturationLevel = 50;
   LOCAL myHSLParams AS HueSaturationLightnessParams
   myHSLParams.hueLevel = 0
   myHSLParams.lightnessLevel = 0
   myHSLParams.saturationLevel = 50

'   HueSaturationLightness myHSL;
'   myHSL.SetParameters(&myHSLParams);
   LOCAL myHSL AS IGdipHueSaturationLightness
   myHSL = pGdip.HueSaturationLightness
   myHSL.SetParameters(myHSLParams)

'   // Draw the image with no change.
'   graphics.DrawImage(&myImage, 20.0, 20.0, srcWidth, srcHeight);
   graphics.DrawImageRect(myImage, 20, 20, srcWidth, srcHeight)

'   // Draw the image with increased saturation.
'   graphics.DrawImage(&myImage, &srcRect, &myMatrix, &myHSL, NULL, UnitPixel);
   graphics.DrawImageFx(myImage, srcRect, myMatrix, myHSL, NOTHING, %UnitPixel)

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

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG

   ' // Create an instance of the CWindow class
   LOCAL pWindow AS IWindow
   pWindow = CLASS "CWindow"
   IF ISNOTHING(pWindow) THEN EXIT FUNCTION

   ' // Create the main window
   LOCAL hwnd AS DWORD
   hwnd = pWindow.CreateWindow(%NULL, "HueSaturationLightnessSetParameters", 0, 0, 0, 0, 0, 0, CODEPTR(WindowProc))
   pWindow.SetClientSize 400, 250
   ' // Center the window
   pWindow.CenterWindow

   ' // Create an instance of the GdiPlus class
   LOCAL pGdip AS IGdiPlus
   pGdip = NewGdiPlus

   ' // Add a GDI+ aware graphic control
   LOCAL hCtrl AS DWORD
   hCtrl = pWindow.AddGraphCtx(hwnd, %IDC_GRCTX, "", 0, 0, pWindow.ClientWidth, pWindow.ClientHeight)
   GraphCtx_Clear(hCtrl, %WHITE)

   ' // Get the memory device context of the graphic control
   LOCAL hdc AS DWORD
   hdc = GraphCtx_GetDc(hCtrl)

   ' // Draw the graphics
   Example_HSLSetParameters(pGdip, hdc)

   ' // Default message pump (you can replace it with your own)
   pWindow.DoEvents(nCmdShow)

END FUNCTION
' ========================================================================================

' ========================================================================================
' Main callback function.
' ========================================================================================
FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG

   SELECT CASE uMsg

      CASE %WM_COMMAND
         SELECT CASE LO(WORD, wParam)
            CASE %IDCANCEL
               ' // If the Escape key has been pressed...
               IF HI(WORD, wParam) = %BN_CLICKED THEN
                  ' // ... close the application by sending a WM_CLOSE message
                  SendMessage hwnd, %WM_CLOSE, 0, 0
               END IF
         END SELECT

      CASE %WM_DESTROY
         ' // End the application
         PostQuitMessage 0
         EXIT FUNCTION

   END SELECT

   ' // Pass unprocessed messages to Windows
   FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)

END FUNCTION
' ========================================================================================


José Roca

 
The following example draws an image twice: once with no change and once with the dark areas made darker. The Matrix object passed to the DrawImage method specifies that the upper-left corner of the adjusted image is at (200, 20).


' ########################################################################################
' Microsoft Windows
' File: CGDIP_Levels.bas
' Contents: GDI+ example
' This version uses the CWindow and CGdiPlus classes, and the GraphCtx graphic control
' Compilers: PBWIN 10.02+, PBCC 6.02+
' Headers: Windows API headers 2.03+
' Copyright (c) 2011 José Roca. Freeware. Use at your own risk.
' Portions Copyright (c) Microsoft Corporation. All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################

#COMPILE EXE
#DIM ALL
%UNICODE = 1
%USEGRAPHCTX = 1

' // Header files for imported files
#INCLUDE ONCE "CWindow.inc"    ' // CWindow class
#INCLUDE ONCE "CGdiPlus.inc"   ' // CGdiPlus class

%IDC_GRCTX = 1001

' ========================================================================================
' The following example draws an image twice: once with no change and once with the dark
' areas made darker. The Matrix object passed to the DrawImage method specifies that the
' upper-left corner of the adjusted image is at (200, 20).
' ========================================================================================
SUB Example_LevelsSetParameters (BYVAL pGdip AS IGdiPlus, BYVAL hdc AS DWORD)

'   Graphics graphics(hdc);
   LOCAL graphics AS IGdipGraphics
   graphics = pGdip.Graphics(hdc)

'   Image myImage(L"Picture.bmp");
   LOCAL myImage AS IGdipImage
   myImage = pGdip.Image("climber.jpg")

'   REAL srcWidth = (REAL)myImage.GetWidth();
'   REAL srcHeight = (REAL)myImage.GetHeight();
   LOCAL srcWidth AS SINGLE
   srcWidth = myImage.GetWidth
   LOCAL srcHeight AS SINGLE
   srcHeight = myImage.GetHeight

'   RectF srcRect(0.0f, 0.0f, srcWidth, srcHeight);
   LOCAL srcRect AS RectF
   srcRect = pGdip.RectF(0, 0, srcWidth, srcHeight)

'   Matrix myMatrix(1.0f, 0.0f, 0.0f, 1.0f, 200.0f, 20.0f);
   LOCAL myMatrix AS IGdipMatrix
   myMatrix = pGdip.Matrix
   myMatrix.Matrix2(1, 0, 0, 1, 200, 20)

'   LevelsParams myLevelsParams;
'   myLevelsParams.highlight = 100; // no change
'   myLevelsParams.midtone = 0;     // no change
'   myLevelsParams.shadow = 20;     // Darken the dark areas.
   LOCAL myLevelsParams AS LevelsParams
   myLevelsParams.highlight = 100   ' // no change
   myLevelsParams.midtone = 0       ' // no change
   myLevelsParams.shadow = 20       ' // Darken the dark areas.

'   Levels myLevels;
'   myLevels.SetParameters(&myLevelsParams);
   LOCAL myLevels AS IGdipLevels
   myLevels = pGdip.Levels
   myLevels.SetParameters(myLevelsParams)

'   // Draw the image with no change.
'   graphics.DrawImage(&myImage, 20.0, 20.0, srcWidth, srcHeight);
   graphics.DrawImageRect(myImage, 20, 20, srcWidth, srcHeight)

'   // Draw the adjusted image.
'   graphics.DrawImage(&myImage, &srcRect, &myMatrix, &myLevels, NULL, UnitPixel);
   graphics.DrawImageFx(myImage, srcRect, myMatrix, myLevels, NOTHING, %UnitPixel)

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

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG

   ' // Create an instance of the CWindow class
   LOCAL pWindow AS IWindow
   pWindow = CLASS "CWindow"
   IF ISNOTHING(pWindow) THEN EXIT FUNCTION

   ' // Create the main window
   LOCAL hwnd AS DWORD
   hwnd = pWindow.CreateWindow(%NULL, "TintSetParameters", 0, 0, 0, 0, 0, 0, CODEPTR(WindowProc))
   pWindow.SetClientSize 400, 250
   ' // Center the window
   pWindow.CenterWindow

   ' // Create an instance of the GdiPlus class
   LOCAL pGdip AS IGdiPlus
   pGdip = NewGdiPlus

   ' // Add a GDI+ aware graphic control
   LOCAL hCtrl AS DWORD
   hCtrl = pWindow.AddGraphCtx(hwnd, %IDC_GRCTX, "", 0, 0, pWindow.ClientWidth, pWindow.ClientHeight)
   GraphCtx_Clear(hCtrl, %WHITE)

   ' // Get the memory device context of the graphic control
   LOCAL hdc AS DWORD
   hdc = GraphCtx_GetDc(hCtrl)

   ' // Draw the graphics
   Example_LevelsSetParameters(pGdip, hdc)

   ' // Default message pump (you can replace it with your own)
   pWindow.DoEvents(nCmdShow)

END FUNCTION
' ========================================================================================

' ========================================================================================
' Main callback function.
' ========================================================================================
FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG

   SELECT CASE uMsg

      CASE %WM_COMMAND
         SELECT CASE LO(WORD, wParam)
            CASE %IDCANCEL
               ' // If the Escape key has been pressed...
               IF HI(WORD, wParam) = %BN_CLICKED THEN
                  ' // ... close the application by sending a WM_CLOSE message
                  SendMessage hwnd, %WM_CLOSE, 0, 0
               END IF
         END SELECT

      CASE %WM_DESTROY
         ' // End the application
         PostQuitMessage 0
         EXIT FUNCTION

   END SELECT

   ' // Pass unprocessed messages to Windows
   FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)

END FUNCTION
' ========================================================================================


José Roca

 
The following example draws an image twice: once with no change and once with a sharpening effect. The Matrix object passed to the DrawImage method specifies that the upper-left corner of the sharpened image is at (200, 20).


' ########################################################################################
' Microsoft Windows
' File: CGDIP_SharpenSetParameters.bas
' Contents: GDI+ example
' This version uses the CWindow and CGdiPlus classes, and the GraphCtx graphic control
' Compilers: PBWIN 10.02+, PBCC 6.02+
' Headers: Windows API headers 2.03+
' Copyright (c) 2011 José Roca. Freeware. Use at your own risk.
' Portions Copyright (c) Microsoft Corporation. All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################

#COMPILE EXE
#DIM ALL
%UNICODE = 1
%USEGRAPHCTX = 1

' // Header files for imported files
#INCLUDE ONCE "CWindow.inc"    ' // CWindow class
#INCLUDE ONCE "CGdiPlus.inc"   ' // CGdiPlus class

%IDC_GRCTX = 1001

' ========================================================================================
' The following example draws an image twice: once with no change and once with a sharpening
' effect. The Matrix object passed to the DrawImage method specifies that the upper-left
' corner of the sharpened image is at (200, 20).
' ========================================================================================
SUB Example_SharpenSetParameters (BYVAL pGdip AS IGdiPlus, BYVAL hdc AS DWORD)

'   Graphics graphics(hdc);
   LOCAL graphics AS IGdipGraphics
   graphics = pGdip.Graphics(hdc)

'   Image myImage(L"Picture.bmp");
   LOCAL myImage AS IGdipImage
   myImage = pGdip.Image("climber.jpg")

'   REAL srcWidth = (REAL)myImage.GetWidth();
'   REAL srcHeight = (REAL)myImage.GetHeight();
   LOCAL srcWidth AS SINGLE
   srcWidth = myImage.GetWidth
   LOCAL srcHeight AS SINGLE
   srcHeight = myImage.GetHeight

'   RectF srcRect(0.0f, 0.0f, srcWidth, srcHeight);
   LOCAL srcRect AS RectF
   srcRect = pGdip.RectF(0, 0, srcWidth, srcHeight)

'   Matrix myMatrix(1.0f, 0.0f, 0.0f, 1.0f, 200.0f, 20.0f);
   LOCAL myMatrix AS IGdipMatrix
   myMatrix = pGdip.Matrix
   myMatrix.Matrix2(1, 0, 0, 1, 200, 20)

'   SharpenParams mySharParams;
'   mySharParams.amount = 30;
'   mySharParams.radius = 50;
   LOCAL mySharParams AS SharpenParams
   mySharParams.amount = 30
   mySharParams.radius = 50

'   Sharpen myShar;
'   myShar.SetParameters(&mySharParams);
   LOCAL myShar AS IGdipSharpen
   myShar = pGdip.Sharpen
   myShar.SetParameters(mySharParams)

'   // Draw the image with no change.
'   graphics.DrawImage(&myImage, 20.0, 20.0, srcWidth, srcHeight);
   graphics.DrawImageRect(myImage, 20, 20, srcWidth, srcHeight)

3   graphics.DrawImageFx(myImage, srcRect, myMatrix, myShar, NOTHING, %UnitPixel)

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

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG

   ' // Create an instance of the CWindow class
   LOCAL pWindow AS IWindow
   pWindow = CLASS "CWindow"
   IF ISNOTHING(pWindow) THEN EXIT FUNCTION

   ' // Create the main window
   LOCAL hwnd AS DWORD
   hwnd = pWindow.CreateWindow(%NULL, "SharpenSetParameters", 0, 0, 0, 0, 0, 0, CODEPTR(WindowProc))
   pWindow.SetClientSize 400, 250
   ' // Center the window
   pWindow.CenterWindow

   ' // Create an instance of the GdiPlus class
   LOCAL pGdip AS IGdiPlus
   pGdip = NewGdiPlus

   ' // Add a GDI+ aware graphic control
   LOCAL hCtrl AS DWORD
   hCtrl = pWindow.AddGraphCtx(hwnd, %IDC_GRCTX, "", 0, 0, pWindow.ClientWidth, pWindow.ClientHeight)
   GraphCtx_Clear(hCtrl, %WHITE)

   ' // Get the memory device context of the graphic control
   LOCAL hdc AS DWORD
   hdc = GraphCtx_GetDc(hCtrl)

   ' // Draw the graphics
   Example_SharpenSetParameters(pGdip, hdc)

   ' // Default message pump (you can replace it with your own)
   pWindow.DoEvents(nCmdShow)

END FUNCTION
' ========================================================================================

' ========================================================================================
' Main callback function.
' ========================================================================================
FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG

   SELECT CASE uMsg

      CASE %WM_COMMAND
         SELECT CASE LO(WORD, wParam)
            CASE %IDCANCEL
               ' // If the Escape key has been pressed...
               IF HI(WORD, wParam) = %BN_CLICKED THEN
                  ' // ... close the application by sending a WM_CLOSE message
                  SendMessage hwnd, %WM_CLOSE, 0, 0
               END IF
         END SELECT

      CASE %WM_DESTROY
         ' // End the application
         PostQuitMessage 0
         EXIT FUNCTION

   END SELECT

   ' // Pass unprocessed messages to Windows
   FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)

END FUNCTION
' ========================================================================================


José Roca

 
The following example draws an image twice: once with no change and once with a cyan tint. The Matrix object passed to the DrawImage method specifies that the upper-left corner of the tinted image is at (200, 20).


' ########################################################################################
' Microsoft Windows
' File: CGDIP_TintSetParameters.bas
' Contents: GDI+ example
' This version uses the CWindow and CGdiPlus classes, and the GraphCtx graphic control
' Compilers: PBWIN 10.02+, PBCC 6.02+
' Headers: Windows API headers 2.03+
' Copyright (c) 2011 José Roca. Freeware. Use at your own risk.
' Portions Copyright (c) Microsoft Corporation. All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################

#COMPILE EXE
#DIM ALL
%UNICODE = 1
%USEGRAPHCTX = 1

' // Header files for imported files
#INCLUDE ONCE "CWindow.inc"    ' // CWindow class
#INCLUDE ONCE "CGdiPlus.inc"   ' // CGdiPlus class

%IDC_GRCTX = 1001

' ========================================================================================
' The following example draws an image twice: once with no change and once with a cyan tint.
' The Matrix object passed to the DrawImage method specifies that the upper-left corner of
' the tinted image is at (200, 20).
' ========================================================================================
SUB Example_TintSetParameters (BYVAL pGdip AS IGdiPlus, BYVAL hdc AS DWORD)

'   Graphics graphics(hdc);
   LOCAL graphics AS IGdipGraphics
   graphics = pGdip.Graphics(hdc)

'   Image myImage(L"Picture.bmp");
   LOCAL myImage AS IGdipImage
   myImage = pGdip.Image("climber.jpg")

'   REAL srcWidth = (REAL)myImage.GetWidth();
'   REAL srcHeight = (REAL)myImage.GetHeight();
   LOCAL srcWidth AS SINGLE
   srcWidth = myImage.GetWidth
   LOCAL srcHeight AS SINGLE
   srcHeight = myImage.GetHeight

'   RectF srcRect(0.0f, 0.0f, srcWidth, srcHeight);
   LOCAL srcRect AS RectF
   srcRect = pGdip.RectF(0, 0, srcWidth, srcHeight)

'   Matrix myMatrix(1.0f, 0.0f, 0.0f, 1.0f, 200.0f, 20.0f);
   LOCAL myMatrix AS IGdipMatrix
   myMatrix = pGdip.Matrix
   myMatrix.Matrix2(1, 0, 0, 1, 200, 20)

'   TintParams myTintParams;
'   myTintParams.hue = 60;  // cyan
'   myTintParams.amount = 40;
   LOCAL myTintParams AS TintParams
   myTintParams.hue = 60   ' // cyan
   myTintParams.amount = 40

'   Tint myTint;
'   myTint.SetParameters(&myTintParams);
   LOCAL myTint AS IGdipTint
   myTint = pGdip.Tint
   myTint.SetParameters(myTintParams)

'   // Draw the image with no change.
'   graphics.DrawImage(&myImage, 20.0, 20.0, srcWidth, srcHeight);
   graphics.DrawImageRect(myImage, 20, 20, srcWidth, srcHeight)

'   // Draw the tinted image.
'   graphics.DrawImage(&myImage, &srcRect, &myMatrix, &myTint, NULL, UnitPixel);
   graphics.DrawImageFx(myImage, srcRect, myMatrix, myTint, NOTHING, %UnitPixel)

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

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG

   ' // Create an instance of the CWindow class
   LOCAL pWindow AS IWindow
   pWindow = CLASS "CWindow"
   IF ISNOTHING(pWindow) THEN EXIT FUNCTION

   ' // Create the main window
   LOCAL hwnd AS DWORD
   hwnd = pWindow.CreateWindow(%NULL, "TintSetParameters", 0, 0, 0, 0, 0, 0, CODEPTR(WindowProc))
   pWindow.SetClientSize 400, 250
   ' // Center the window
   pWindow.CenterWindow

   ' // Create an instance of the GdiPlus class
   LOCAL pGdip AS IGdiPlus
   pGdip = NewGdiPlus

   ' // Add a GDI+ aware graphic control
   LOCAL hCtrl AS DWORD
   hCtrl = pWindow.AddGraphCtx(hwnd, %IDC_GRCTX, "", 0, 0, pWindow.ClientWidth, pWindow.ClientHeight)
   GraphCtx_Clear(hCtrl, %WHITE)

   ' // Get the memory device context of the graphic control
   LOCAL hdc AS DWORD
   hdc = GraphCtx_GetDc(hCtrl)

   ' // Draw the graphics
   Example_TintSetParameters(pGdip, hdc)

   ' // Default message pump (you can replace it with your own)
   pWindow.DoEvents(nCmdShow)

END FUNCTION
' ========================================================================================

' ========================================================================================
' Main callback function.
' ========================================================================================
FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG

   SELECT CASE uMsg

      CASE %WM_COMMAND
         SELECT CASE LO(WORD, wParam)
            CASE %IDCANCEL
               ' // If the Escape key has been pressed...
               IF HI(WORD, wParam) = %BN_CLICKED THEN
                  ' // ... close the application by sending a WM_CLOSE message
                  SendMessage hwnd, %WM_CLOSE, 0, 0
               END IF
         END SELECT

      CASE %WM_DESTROY
         ' // End the application
         PostQuitMessage 0
         EXIT FUNCTION

   END SELECT

   ' // Pass unprocessed messages to Windows
   FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)

END FUNCTION
' ========================================================================================