L_CopyBitmapRect

#include "l_bitmap.h"

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

pBITMAPHANDLE pBitmapDst;

/* pointer to the destination bitmap handle */

pBITMAPHANDLE pBitmapSrc;

/* pointer to the source bitmap handle */

L_UINT uStructSize;

/* size in bytes, of the structure pointed to by pBitmapDst */

L_INT nCol;

/* x coordinate origin of the rectangle to copy */

L_INT nRow;

/* Y coordinate 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) */

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

Parameter

Description

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.

pBitmapSrc

Pointer to the bitmap handle referencing the source bitmap.

uStructSize

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

nCol

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

nRow

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

uWidth

Width of the rectangle to copy (in pixels).

uHeight

Height of the rectangle to copy (in pixels).

Returns

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

LTKRN

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Win32, x64.

See Also

Functions:

L_AutoTrimBitmap, L_GetAutoTrimRect, L_TrimBitmap,

 

L_CopyBitmap, L_CopyBitmapData,

 

L_CopyBitmapHandle

Topics:

Raster Image Functions: Copying Images

 

Raster Image Functions: Palettes

 

Raster Image Functions: Using the Clipboard

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;
}