ImageMan DLL Suite Version 8Submit feedback on this topic   

Writing an Image to Memory

ImageMan can also be used to export images to memory blocks. To do this, an application uses the ImgXBeginWriteMem/ImgXEndWriteMem function pair instead of the ImgXBeginWrite/ImgXEndWrite functions. The following example illustrates writing a DIB to a TIFF file in memory:

 

#include "imgx.h"

HANDLE hJob, hMemBlk;

XINFO xInfo;

DWORD dwSize;

...

// lpBitmapInfo points to a BITMAPINFO structure

// lpRasterData points to our image data in DIB format

// xInfo has been initialized

hJob = ImgXBeginWriteMem("tif",lpBitmapInfo,NULL,&xInfo,NULL,0);

ImgXWriteBlock( hJob, nLines, lpRasterData, &xInfo );

ImgXEndWriteMem( hJob, &xInfo, &hMemBlk, &dwSize );

// hMemBlk now contains the handle of the memory block

// containing the image, and dwSize is the size of the

// image, in bytes. It is up to the calling app

// to free hMemBlk using GlobalFree before the app exits.

//

...

If we haven't said enough times already, we'll say it again here: It is up to your application to free the memory block returned from the ImgXEndWriteMem function. Failure to do so will result in a severe memory leak in your application, which is a bad thing.

 

 


© 1995-2004 Data Techniques, Inc. All rights reserved.