LRasterPaint::PickColor

Summary

Gets the color at the specified position.

Syntax

#include "Ltwrappr.h"

L_INT LRasterPaint::PickColor(UserDC, nX, nY, pcrDestColor)

Parameters

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 from which to get the color.

L_INT nY

Y -coordinate of the position from which to get the 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 LRasterPaint::SetMetrics, 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.

Required DLLs and Libraries

See Also

Functions

Topics

Example

L_INT LRasterPaint_PickColorExample( CWnd* pWnd, LBitmapBase*  pLBitmap, L_INT nX, L_INT nY, COLORREF *pcrDestColor )  
{ 
   L_INT          nRet; 
   LRasterPaint   rstp; 
   CDC*           pDC = pWnd->GetDC() ; 
   HPALETTE       hPalette = NULL;  
   RECT           rcSrc, rcDest ; 
   L_TCHAR        buffer [ 80 ] ; 
 
   /* Initiate the Paint toolkit */ 
   nRet = rstp.Initialize (); 
   if(nRet != SUCCESS) 
      return nRet; 
 
   pLBitmap->Paint()->SetDC( pDC->m_hDC ); 
 
   /* Create restriction palette (if needed) */ 
   pLBitmap->SetPalette( pLBitmap->CreatePaintPalette( pDC->m_hDC ) ); 
 
   /* Set the bitmap painting coordinates  */ 
   SetRect ( &rcSrc, 0, 0, pLBitmap->GetWidth( ), pLBitmap->GetHeight( ) ) ; 
 
   CopyRect ( &rcDest, &rcSrc ) ; 
 
   /* paint the bitmap */ 
   pLBitmap->Paint()->SetDC( pDC->m_hDC ); 
   pLBitmap->SetSrcRect( &rcSrc ); 
   pLBitmap->SetDstRect( &rcDest ); 
   pLBitmap->Paint()->PaintDC(); 
 
   /* Set the extents of the DC that we are going to pick the color from */ 
   nRet = rstp.SetDCExtents ( &rcDest ) ; 
   if(nRet != SUCCESS) 
      return nRet; 
 
   /* Get the color value */ 
   nRet = rstp.PickColor ( pDC->m_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 ) ) ; 
 
   pWnd->SetWindowText ( buffer ) ; 
 
   pLBitmap->Paint()->SetDC(NULL); 
 
   /* Release the DC */ 
   pWnd->ReleaseDC( pDC ) ; 
 
   /* Delete the font object */ 
   DeleteObject ( (HPALETTE ) hPalette ) ; 
 
   /* Free the paint tools handle */ 
   nRet = rstp.Free ( ) ; 
   if(nRet != SUCCESS) 
      return nRet; 
 
   return SUCCESS ; 
} 
Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS DigitalPaint C++ Class Library Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.