Low-Level DigitalPaint: Filling an Area

Start with the project you created in Low-Level DigitalPaint: Creating a Region.

  1. Add the following item to the popup menu "Painting Test " that you added to the main menu:
    • &Painting Test
    • &Fill
    • with ID = IDM_PAINTTEST_FILL
  2. Add the following function before the OnOpen function definition:
    static L_VOID OnFill ( HWND hWnd, pPAINTHANDLE pPaint ) 
    { 
       HDC hDC ; 
       PAINTSHAPE shape ; 
       PAINTFILL fill ; 
       RECT rcShape ; 
       RECT rcDCExtents ; 
        
       // Get device context to draw on 
       hDC = GetDC ( hWnd ) ; 
       // Set the required shape properties 
       shape.nSize  = sizeof ( PAINTSHAPE ) ; 
       shape.dwMask = PSF_BORDERWIDTH     | 
       PSF_BORDERCOLOR     | 
       PSF_BACKGROUNDCOLOR ; 
        
       shape.nBorderWidth = 10 ; 
       shape.crBorderColor = RGB ( 255, 0, 0 ) ; 
       shape.crBackgroundColor = RGB ( 255, 0, 0 ) ; 
       // Set the new shape properties 
       L_PntSetProperty ( pPaint, PAINT_GROUP_SHAPE, &shape ) ; 
       // Set the coordinates with respect to the DC dimensions 
       SetRect ( &rcShape, 10, 10, 60, 60 ) ; 
       // Use the current shape properties to draw an ellipse to the DC (hDC) 
       L_PntDrawShapeEllipse ( pPaint, hDC, &rcShape ) ; 
       SetRect ( &rcShape, 100, 10, 150, 60 ) ; 
       L_PntDrawShapeEllipse ( pPaint, hDC, &rcShape ) ; 
       SetRect ( &rcShape, 60, 60, 95, 95 ) ; 
       L_PntDrawShapeRectangle ( pPaint, hDC, &rcShape ) ; 
       SetRect ( &rcShape, 10, 100, 60, 150 ) ; 
       L_PntDrawShapeEllipse ( pPaint, hDC, &rcShape ) ; 
       SetRect ( &rcShape, 100, 100, 150, 150 ) ; 
       L_PntDrawShapeEllipse ( pPaint, hDC, &rcShape ) ; 
       // Get the destination DC dimensions 
       GetClientRect ( hWnd, &rcDCExtents ) ; 
       // Set the toolkit user DC extents 
       L_PntSetDCExtents ( pPaint, &rcDCExtents ) ; 
       // Set the required fill properties 
       fill.nSize  = sizeof ( PAINTFILL ) ; 
       fill.dwMask = PFF_STYLE ; 
       fill.nStyle = PAINT_FILL_STYLE_GRADIENT ; 
       // Set the new fill properties 
       L_PntSetProperty ( pPaint, PAINT_GROUP_FILL, &fill ) ; 
       // Fill the target area 
       L_PntFillColorReplace ( pPaint, hDC, RGB ( 255, 0, 0 ) ) ; 
       // Release the device context 
       ReleaseDC ( hWnd, hDC ) ; 
    } 
  3. Add the following line after the "return 0L ;" of the "case IDM_PAINTTEST_REGION:" statement:

    case IDM_PAINTTEST_FILL:   
                   OnFill ( hWnd, pPaint ) ;   
                   return 0L ;  

  4. Compile and run the project by selecting Build->Execute tutorial.exe from the menu.

  5. Go to the "File" menu and use the "Open" item to open an image.
  6. Go to the "Painting Test" and select the "Fill" item. This will replace all the RGB ( 255, 0, 0 ) color using the current fill group properties.
Help Version 22.0.2022.12.7
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Digital Paint C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.