L_PaintRgnDCBuffer

Summary

Paints image data into a device context from a buffer. This function works the same as L_PaintDCBuffer, except that only the bitmap region is painted.

Syntax

#include "l_bitmap.h"

L_LTDIS_API L_INT L_PaintRgnDCBuffer (hDC, pBitmap, pSrc, pClipSrc, pDst, pClipDst, uROP3, pBuffer, nRow, nCount)

Parameters

L_HDC hDC

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

pBITMAPHANDLE pBitmap

Pointer to the bitmap handle referencing the bitmap that has the region to paint.

L_RECT* pSrc

Pointer to the Windows RECT structure that specifies the part of the bitmap to use as the display source.

The coordinates in the RECT structure are relative to the bitmap. You can pass NULL to use the default, which matches the bitmap.

L_RECT* pClipSrc

Pointer to the Windows RECT structure that specifies the portion of the display source to paint. Generally, this is used for updating the display when part of the source bitmap has changed.

The coordinates in the RECT structure are relative to the bitmap. You can pass NULL to use the default, which matches the bitmap.

L_RECT* pDst

Pointer to the Windows RECT structure that determines how the source rectangle is scaled and how the image is positioned in the device context.

The coordinates in the RECT structure are relative to the device context. There is no default for this parameter. You must specify the RECT structure.

L_RECT* pClipDst

Pointer to the Windows RECT structure that specifies the portion of the display rectangle to paint. Generally, this is used for updating changes in the display surface, such as when a user moves another window, uncovering a part of the image that had been covered up.

The coordinates in the RECT structure are relative to the device context. You can pass NULL to use the default, which matches the device context. In most cases, however, you should use the rectangle returned by the Windows WM_PAINT message.

L_UINT32 uROP3

The Windows ROP code that determines how the destination rectangle is updated. This parameter takes the same codes as the Windows BitBlt function. For ordinary painting, use SRCCOPY.

L_UCHAR * pBuffer

Pointer to the buffer that contains the image data to paint.

L_INT nRow

The first row to paint. The painted portion of any row may be limited by the RECT parameters.

L_INT nCount

The number of rows to paint. The painted portion of any row may be limited by the RECT parameters.

Returns

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

Comments

The bitmap must be allocated before you can create a region for it. Therefore, if you use this function in a paint-while-load routine, you must use your callback function to create the region after the bitmap is allocated.

Required DLLs and Libraries

Platforms

Win32, x64.

See Also

Functions

Topics

Example

Creates a region in the image, then gets the data one line at a time and paints it.

L_INT PaintRgnDCBufferExample(L_HWND hWnd, pBITMAPHANDLE pBitmap) 
{ 
   L_INT    nRet = SUCCESS; 
   HDC      hdc;                    /* Device context for the current window */ 
   RECT     rcDest;                 /* Destination rectangle for painting */ 
   HPALETTE hSavedPalette = NULL;   /* Temporary copy of the current system palette */ 
   HPALETTE hOurPalette = NULL;     /* The palette that we will use to paint */ 
   RECT     rcRgn; 
   L_INT    x; 
 
   SetRect(&rcRgn, BITMAPWIDTH(pBitmap) * 1 / 4, BITMAPHEIGHT(pBitmap) * 1 / 4, 
      BITMAPWIDTH(pBitmap) * 3 / 4, BITMAPHEIGHT(pBitmap) * 3 / 4); 
   nRet = L_SetBitmapRgnEllipse(pBitmap, NULL, &rcRgn, L_RGN_SET); 
   if (nRet != SUCCESS) 
      return nRet; 
 
   /* Get the device context */ 
   hdc = GetDC(hWnd); 
 
   /* Set the destination rectangle to be the same as the bitmap. 
   Other painting rectangles can take defaults. */ 
   GetClientRect(hWnd, &rcDest); 
 
   /* Create the palette that we will use to paint */ 
   hOurPalette = L_CreatePaintPalette(hdc, pBitmap); 
 
   /* Select our palette and save the old one */ 
   hSavedPalette = SelectPalette(hdc, hOurPalette, FALSE); 
 
   /* Realize our palette */ 
   RealizePalette(hdc); 
 
   /* Paint the image */ 
   L_AccessBitmap(pBitmap); 
   for (x = 0; x < pBitmap->Height; x++) 
   { 
      L_UCHAR* pBuf = (L_UCHAR*)malloc(pBitmap->BytesPerLine); 
      nRet = (L_INT)L_GetBitmapRow(pBitmap, pBuf, x, pBitmap->BytesPerLine); 
      if (nRet < 1) 
         return nRet; 
 
      nRet = L_PaintRgnDCBuffer(hdc, pBitmap, NULL, NULL, &rcDest, NULL, SRCCOPY, pBuf, x, 1); 
      if (nRet != SUCCESS) 
         return nRet; 
   } 
 
   L_ReleaseBitmap(pBitmap); 
 
   /* Restore the old palette */ 
   SelectPalette(hdc, hSavedPalette, FALSE); 
 
   /* Delete the newly created palette */ 
   DeleteObject(hOurPalette); 
 
   /* Release the device context */ 
   ReleaseDC(hWnd, hdc); 
 
   return nRet; 
} 

Help Version 22.0.2023.7.11
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

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