L_CopyBitmapRect

#include "l_bitmap.h"

L_LTKRN_API L_INT L_CopyBitmapRect(pBitmapDst, pBitmapSrc, uStructSize, nCol, nRow, uWidth, uHeight)

Copies a portion of a bitmap to create another bitmap that is the size of the rectangle that you specify.

Parameters

pBITMAPHANDLE pBitmapDst

Pointer to the bitmap handle referencing the destination bitmap.

You do not have to initialize the bitmap handle; the L_CopyBitmapRect function initializes it for you.

pBITMAPHANDLE pBitmapSrc

Pointer to the bitmap handle referencing the source bitmap.

L_UINT uStructSize

Size in bytes, of the structure pointed to by pBitmapDst, for versioning. Use sizeof(BITMAPHANDLE).

L_INT nCol

The X coordinate of the pixel within the source bitmap that is the origin of the rectangle to copy.

L_INT nRow

The Y coordinate of the pixel within the source bitmap that is the origin of the rectangle to copy.

L_UINT uWidth

Width of the rectangle to copy (in pixels).

L_UINT uHeight

Height of the rectangle to copy (in pixels).

Returns

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

Comments

This function duplicates the original bitmap's palette, if one is required in the new bitmap.

This function uses bitmap coordinates to specify the area to be copied. Therefore, you must account for the view perspective of the bitmap. For information about bitmap coordinates, refer to Accounting for View Perspective.

If a region is defined for the source bitmap, the region is also copied, and the region is clipped if necessary.

Required DLLs and Libraries

Platforms

Win32, x64, Linux.

See Also

Functions

Topics

Example

This example uses L_CopyBitmapRect to copy a rectangle that would
appear in the upper left part of the displayed image.

L_INT CopyBitmapRectExample(L_TCHAR* szFilename, BITMAPHANDLE* pBitmap) 
{ 
   BITMAPHANDLE   TmpBitmap; /* Temporary bitmap */ 
   L_INT          XOffset; /* Column offset of the rectangle to process */ 
   L_UINT         XSize; /* Pixel width of the rectangle to process */ 
   L_INT          YOffset; /* Row offset of the rectangle to process */ 
   L_UINT         YSize; /* Pixel height of the rectangle to process */ 
   RECT           rc;  /* rect for converting coordinates */ 
   L_INT          nRet = 1; 
 
   /* Load the bitmap, at its own bits per pixel */ 
   nRet = L_LoadBitmap (szFilename, &TmpBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL); 
   if(nRet != SUCCESS) 
      return nRet; 
   /* Specify a rectangle in the top left part of the displayed image */ 
   XOffset = BITMAPWIDTH (&TmpBitmap) / 8; 
   XSize = BITMAPWIDTH (&TmpBitmap) / 3; 
   YOffset = BITMAPHEIGHT (&TmpBitmap) / 8; 
   YSize = BITMAPHEIGHT (&TmpBitmap) / 3; 
   rc.left = XOffset; 
   rc.top = YOffset; 
   rc.right = XSize + rc.left; 
   rc.bottom = YSize + rc.top; 
   /* Make sure the coordinates are in the ViewPerspective of the Bitmap */ 
   nRet = L_RectToBitmap ( &TmpBitmap, TOP_LEFT, &rc ); 
   if(nRet != SUCCESS) 
   { 
      L_FreeBitmap(&TmpBitmap); 
      return nRet; 
   } 
 
   XOffset = rc.left; 
   YOffset = rc.top; 
   XSize = rc.right - rc.left; 
   YSize = rc.bottom - rc.top; 
   /* Copy the rectangle */ 
   if(pBitmap->Flags.Allocated) 
      L_FreeBitmap(pBitmap); 
   nRet = L_CopyBitmapRect(pBitmap, &TmpBitmap, sizeof(BITMAPHANDLE), XOffset, YOffset, XSize, YSize); 
   /* Free the temporary bitmap */ 
   L_FreeBitmap(&TmpBitmap); 
   return nRet; 
} 

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

LEADTOOLS Raster Imaging C API Help

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.