L_ReadFileTagMemory
#include "l_bitmap.h"
L_INT32 EXT_FUNCTION L_ReadFileTagMemory(pBuffer, uTag, pType, pCount, pData, nBufferSize, pLoadOptions)
/* pointer to the file in memory */ | |
L_UINT16 uTag; |
/* tag to identify the data in the TIFF file */ |
/* address of the variable for the data type */ | |
/* address of the variable for the count */ | |
/* pointer to the buffer for the data */ | |
L_INT32 nBufferSize; |
/* size of the file in memory (in bytes) */ |
pLOADFILEOPTION pLoadOptions; |
/* pointer to optional extended load options */ |
Gets the specified tagged data from a TIFF file in memory. This function is provided to support TIFF tags that you define.
Parameter |
Description |
|
pBuffer |
Pointer to the file in memory. |
|
uTag |
Tag to identify the data in the TIFF file. Use the same tag that you specified in the L_SetTag function. |
|
pType |
Address of the variable to be updated with the tagged data type. The following are possible values: |
|
|
Value |
Meaning |
|
TAG_BYTE |
[1] Byte. |
|
TAG_ASCII |
[2] Byte in the range of 0 to 255. |
|
TAG_SBYTE |
[6] Byte used as signed number in the range of -128 to +127. |
|
TAG_UNDEFINED |
[7] Byte, with application-defined usage. |
|
TAG_SHORT |
[3] Two bytes, unsigned. |
|
TAG_SSHORT |
[8] Two bytes, signed. |
|
TAG_LONG |
[4] Four bytes, unsigned. |
|
TAG_SLONG |
[9] Four bytes, signed. |
|
TAG_RATIONAL |
[5] Eight bytes, used as a pair of unsigned long integers, where the first number is the numerator and the second is the denominator of a fraction. |
|
TAG_SRATIONAL |
[10] Eight bytes, used as a pair of signed long integers, where the first number is the numerator and the second is the denominator of a fraction. |
|
TAG_FLOAT |
[11] Four bytes used as a floating point number. |
|
TAG_DOUBLE |
[12] Eight bytes used as a double-precision floating point number. |
pCount |
Address of the variable to be updated with the count of data items. The count is based on the tagged data type. For example, if the count is 2 and the data type is TAG_DOUBLE, the required buffer size is 16. |
|
pData |
Pointer to the buffer to be updated with the data. You can pass NULL if you want to use this function's return value to determine the required buffer size. |
|
nBufferSize |
Size of the file in memory (in bytes). |
|
pLoadOptions |
Pointer to optional extended load options. Pass NULL to use the default load options. |
Returns
>=0 |
Length of the tagged data, in bytes. |
< 0 |
An error occurred. Refer to Return Codes. |
Comments
It is often convenient to call this function twice, as follows:
1. |
Call the function the first time, specifying NULL in the pData parameter, and using the return value to determine the required size of the buffer. |
2. |
Allocate the buffer. |
3. |
Call the function the second time, passing a pointer to your buffer in the pData parameter. |
For general information about TIFF tags, refer to Implementing TIFF Comments and Tags.
Required DLLs and Libraries
LTFIL 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, Windows CE.
See Also
Functions: |
|
Topics: |
Example
/* This example specifies a tag for recording the position of a company logo on an image.
It sets the tag with L_SetTag; saves the image as a TIFF file in memory; then uses
L_ReadFileTagMemory to read the tag from the file in memory. */
void TestReadTagMem(pBITMAPHANDLE pBitmap)
{
L_TCHAR msgbuf[80]; /* buffer for the message string */
L_UINT16 LogoPosition = 0x8001; /* my private tag */
L_UINT16 TagType = TAG_SSHORT; /* tagged data type */
L_UINT32 TagCount = 4; /* count of data items */
L_INT TagData[] = {5, 5, 24, 37,};
L_VOID L_FAR * pTagData = &TagData; /* pointer to the buffer containing tagged data */
HGLOBAL hBuf; /* handle to the buffer for the file*/
L_INT32 BufferSize; /* required size of the file buffer */
HGLOBAL hFileInMemory; /* memory handle for the file */
L_UINT32 uMemSize; /* size of the file in memory */
L_CHAR L_FAR *pData; /* pointer to the file in memory */
/* Set the tag data to be saved */
L_SetTag(LogoPosition, TagType, TagCount, pTagData);
/* Save the image as a TIFF file in memory */
L_SaveBitmapMemory(&hFileInMemory, pBitmap, FILE_TIF, pBitmap->BitsPerPixel, 0, &uMemSize, NULL);
/* Get the pointer to the memory-resident file */
pData = (L_CHAR L_FAR *) GlobalLock (hFileInMemory);
/* Clear the variables so that we can validate the data */
TagType = 0;
TagCount = 0;
TagData[0] = 0;
TagData[1] = 0;
TagData[2] = 0;
TagData[3] = 0;
/* Get the required size of the buffer for the tagged data */
BufferSize = L_ReadFileTagMemory(pData, LogoPosition, &TagType, &TagCount, NULL, uMemSize, NULL);
/* Allocate and lock the buffer */
if ((TagType == TAG_SSHORT) && (BufferSize > 0))
{
hBuf = GlobalAlloc(GMEM_MOVEABLE, BufferSize);
pTagData = GlobalLock( hBuf );
}
else
{
GlobalUnlock (hFileInMemory);
GlobalFree (hFileInMemory);
return;
}
/* Get the tagged data */
L_ReadFileTagMemory(pData, LogoPosition, &TagType, &TagCount, pTagData, uMemSize, NULL);
/* Display a message showing the data */
if ((TagType == TAG_SSHORT) && (TagCount == 4))
{
wsprintf(msgbuf, TEXT("X = %d\nY= %d\nWidth = %d\nHeight = %d"),
((L_INT L_FAR *)pTagData)[0],
((L_INT L_FAR *)pTagData)[1],
((L_INT L_FAR *)pTagData)[2],
((L_INT L_FAR *)pTagData)[3]);
MessageBox (NULL, msgbuf, TEXT("Logo Position"), MB_OK);
}
/* Free memory that we no longer need */
GlobalUnlock (hBuf);
GlobalFree(hBuf);
GlobalUnlock (hFileInMemory);
GlobalFree (hFileInMemory);
return;
}