L_PntPickColor

#include "LtPnt.h"

L_LTPNT_API L_INT L_PntPickColor(pPaint, UserDC, nX, nY, pcrDestColor)

Gets the color at the specified position.

Parameters

pPAINTHANDLE pPaint

Pointer to a paint handle.

L_HDC UserDC

Handle to a device context, such as a screen, to use as a display surface. This parameter can also be NULL. . The mapping mode of the device context must be MM_TEXT.

L_INT nX

X-coordinate of the position to get its color.

L_INT nY

Y-coordinate of the position to get its color.

COLORREF * pcrDestColor

Pointer to a COLORREF value to be updated with the color at the specified position.

Returns

Value Meaning
SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.

Comments

If the user has set a bitmap in the toolkit, using the function L_PntSetMetrics, then the toolkit will get the color at the specified position of the bitmap. Otherwise, the toolkit will get the color from the specified position of the specified device context.

If the UserDC is not NULL, the user should set the DC boundaries before calling this function, by calling L_PntSetDCExtents.

Required DLLs and Libraries

See Also

Functions

Topics

Example

L_INT PntPickColorExample(HWND            hWnd, 
                                         pBITMAPHANDLE   pBitmap, 
                                         L_INT           nX, 
                                         L_INT           nY, 
                                         COLORREF*       pcrDestColor) 
{ 
   L_INT nRet; 
   pPAINTHANDLE pPaint ; 
   HDC          hDC ; 
   HPALETTE     hPalette ;  
   RECT         rcSrc, rcDest ; 
   L_TCHAR      buffer [ 80 ] ; 
 
   /* Initiate the Paint toolkit */ 
   nRet = L_PntInit ( &pPaint ); 
   if ( SUCCESS != nRet) 
   { 
      return nRet; 
   } 
 
   /* Get device context */ 
   hDC = GetDC ( hWnd ) ; 
 
   /* Create restriction palette (if needed) */ 
   hPalette = L_CreatePaintPalette ( hDC, pBitmap ) ; 
 
   /* Select the bitmap and the restriction palette into the toolkit */ 
   nRet = L_PntSetMetrics ( pPaint, NULL, NULL, hPalette ) ; 
   if(nRet != SUCCESS) 
      return nRet; 
 
   /* Set the bitmap painting coordinates  */ 
   SetRect ( &rcSrc, 0, 0, BITMAPWIDTH ( pBitmap ), BITMAPHEIGHT ( pBitmap ) ) ; 
 
   CopyRect ( &rcDest, &rcSrc ) ; 
 
   /* Paint the bitmap to the screen */ 
 
   nRet = L_PaintDC ( hDC, pBitmap, &rcSrc, NULL, &rcDest, NULL, SRCCOPY ) ; 
   if(nRet != SUCCESS) 
      return nRet; 
 
   /* Set the extents of the DC that we are going to pick the color from */ 
   nRet = L_PntSetDCExtents ( pPaint, &rcDest ) ; 
   if(nRet != SUCCESS) 
      return nRet; 
 
   /* Get the color value */ 
   nRet = L_PntPickColor ( pPaint, hDC, nX, nY, pcrDestColor ) ; 
   if(nRet != SUCCESS) 
      return nRet; 
 
   /* Display the results */ 
   wsprintf ( buffer, 
             TEXT("R:%d G:%d B:%d"), 
             GetRValue ( *pcrDestColor ), 
             GetGValue ( *pcrDestColor ), 
             GetBValue ( *pcrDestColor ) ) ; 
 
   SetWindowText ( hWnd, buffer ) ; 
 
   /* Release the DC */ 
   ReleaseDC ( hWnd, hDC ) ; 
 
   /* Delete the font object */ 
   DeleteObject ( (HPALETTE ) hPalette ) ; 
 
   /* Free the paint tools handle */ 
   L_PntFree ( pPaint ) ; 
 
   return SUCCESS ; 
} 
Help Version 20.0.2020.4.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Digital Paint C API Help