L_SliceBitmap

#include "l_bitmap.h"

L_INT EXT_FUNCTION L_SliceBitmap(pBitmap, pOptions, pnDeskewAngle, pfnCallback, pUserData)

pBITMAPHANDLE pBitmap;

/* pointer to the bitmap */

pSLICEBITMAPOPTIONS pOptions;

/* pointer to a structure */

L_INT32 L_FAR * pnDeskewAngle;

/* address of the deskew angle variable to be updated */

BITMAPSLICECALLBACK pfnCallback;

/* callback function */

L_VOID L_FAR * pUserData;

/* pointer to more parameters for the callback */

Extracts individual slices from radiographic scanned film. This function is available in the Raster Pro and above toolkits.

Parameter

Description

pBitmap

Pointer to the bitmap handle referencing the bitmap to be sliced.

pOptions

Pointer to the SLICEBITMAPOPTIONS structure that LEADTOOLS uses to slice the bitmap.

pnDeskewAngle

NULL or the address of the variable to be updated with the amount that the function rotates the sliced bitmap. The amount of rotation is expressed in hundredths of degrees. For example, 500 means 5 degrees clockwise. You can pass NULL if you do not need to check the amount of rotation. This field is updated only if SLC_DESKEW is selected from pSLICEBITMAPOPTIONS flag parameter.

pfnCallback

Pointer to a callback function used retrieve each slice's data and information.

This callback function must return a positive number or an error code (negative number). If it returns an error code, the slicing process will stop, and the code will be passed back as the return code.

The callback function must adhere to the function prototype described in the BITMAPSLICECALLBACK function.

pUserData

Void pointer that you can use to pass one or more additional parameters that the callback function needs.

To use this feature, assign a value to a variable or create a structure that contains as many fields as you need. Then, in this parameter, pass the address of the variable or structure, casting it to L_VOID L_FAR *. The callback function, which receives the address in its own pUserData parameter, can cast it to a pointer of the appropriate data type to access your variable or structure.

If the additional parameters are not needed, you can pass NULL in this parameter.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

This function is designed to extract the individual slices from radiographic scanned film. The image below shows an example of these radiographic images before and after applying the L_SliceBitmap function where we use the output data to draw a white line around each separate slice.

image\BeforeSliceBitmap.gif

Film Before Function Is Called

image\AfterSliceBitmap.gif

Film After Function Is Called

To update a status bar or detect a user interrupt during execution of this function, refer to L_SetStatusCallback.

This function supports 12 and 16-bit grayscale and 48 and 64-bit color images. Support for 12 and 16-bit grayscale and 48 and 64-bit color images is available only in the Document/Medical toolkits.

This function does not support signed data images. It returns the error code ERROR_SIGNED_DATA_NOT_SUPPORTED if a signed data image is passed to this function.

Required DLLs and Libraries

LTIMG

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

Windows 95 / 98 / Me, Windows 2000 / XP.

See Also

Functions:

BITMAPSLICECALLBACK

Topics:

Processing an Image

 

Raster Image Functions: Creating and Maintaining Lists of Images

 

Raster Image Functions: Creating and Using a Region

 

Raster Image Functions: Processing an Image

Example

/*The following example finds all the slices inside some radiographic scanned film and saves them to the selected folder:*/

typedef struct tagSLICEBITMAPUSERINFO
{
   L_UCHAR SlicesFolder[L_MAX_PATH];
   L_UINT  SlicesCount;

}
SLICEBITMAPUSERINFO, L_FAR * pSLICEBITMAPUSERINFO;

L_INT L_EXPORT EXT_CALLBACK ExampleSliceCB
   (
   pBITMAPHANDLE pBitmap, 
   LPRECT lpSliceRect, 
   L_INT  nAngle,
   L_VOID L_FAR * pUserData
   )
{
   pSLICEBITMAPUSERINFO pSlicesUserInfo;
   L_CHAR               szDirectory[L_MAXPATH];
   L_CHAR               S[30];
   L_INT                nRet;
   
   pSlicesUserInfo = (pSLICEBITMAPUSERINFO)pUserData;
   
   lstrcpy(szDirectory, pSlicesUserInfo->SlicesFolder);
   strcat(szDirectory, TEXT("\\"));
   wsprintf(S,TEXT("%d.bmp"), (pSlicesUserInfo->SlicesCount));
   strcat(szDirectory, S);

   nRet = L_SaveFile(szDirectory, pBitmap, FILE_BMP, 24, 0, SAVEFILE_FIXEDPALETTE, NULL, NULL, NULL  );
   if(nRet == SUCCESS)
   {
      pSlicesUserInfo->SlicesCount++;
      L_FreeBitmap(pBitmap);
      GlobalFree(pBitmap);
   }
   return SUCCESS;
}
L_VOID ExampleSliceBitmap(HWND hWnd, pBITMAPHANDLE pBitmap, LPSTR SlicesFolder)
{
   SLICEBITMAPOPTIONS      Options;
   SLICEBITMAPUSERINFO     UserData;
   L_INT                   nRet;
   L_CHAR                  S[30] = TEXT("");
   L_CHAR                  Message[512] = TEXT("");

   Options.uStructSize = sizeof(SLICEBITMAPOPTIONS);
   // Deskew the sliced image, the deskew angle is located between -5 and 5 degrees
   Options.uFlags = SLC_DESKEW|SLC_DSKW_LINEAR|SLC_CUTSLICES;
   Options.uMaxDeskewAngle = 500;
   Options.crFill = RGB(0,0,0);
   
   memcpy(UserData.SlicesFolder, SlicesFolder, L_MAXPATH);
   UserData.SlicesCount = 0;

   nRet = L_SliceBitmap(pBitmap, &Options, NULL, ExampleSliceCB, (L_VOID L_FAR *)(&UserData));  
   if(nRet == SUCCESS)
   {
      lstrcpy(Message, TEXT("The number of sliced image is"));
      wsprintf(S, TEXT("%d"), (UserData.SlicesCount));
      strcat(Message, S );
      MessageBox(hWnd, Message, TEXT("SliceBitmap Example"), MB_OK);
   }
}