If there is a TIFF file in memory you can load it into a DIB or bitmap using the Black Ice Imaging Toolkits. This functionality is useful for network based applications to avoid file I/O. You can also use this functionality to load an image from a database.
[C++]
/* Use OpenTiffInMemory from BiTiff.dll */
#include “BiTiff.h”
HANDLE hChain;
/* 1. parameter: Handle of the memory block
2. parameter: Size of the memory block in bytes
3. parameter: Open memory for reading
If hChain is NULL loading has failed. */
hChain = OpenTiffInMemory(hMemBlock, GlobalSize(hMemBlock),
T_READ);
if (hChain)
{
// Registers the nImage-th image.
if (!GetTiffImage(hChain, 0)) // Registering OK.
{
CloseTiffFile(hChain);
GlobalFree(hMemBlock);
AfxMessageBox(_T("Error registring TIFF image."),
MB_OK|MB_ICONERROR);
return;
}
// Load the first page from the TIFF image.
// To retrieve a DIB from the TIFF file, use
// LoadTiffChainIntoDIB function from the BiTiff.dll.
// In this case you don't have to use the GetTiffImage
// function before calling LoadTiffChainIntoDIB.
HBITMAP hBmp = LoadTiffChainIntoBitmap(hChain, 0);
if (hBmp)
{
// Display the bitmap on the dialog
CloseTiffFile(hChain);
}
else
AfxMessageBox(_T("Error opening TIFF in the
memory."), MB_OK|MB_ICONERROR);
GlobalFree(hMemBlock);
[C#]
/* Use LoadTiffFromMemory from BiTiff.ocx */
long hDib;
/* 1. parameter: Handle of the memory block (long)
2. parameter: Image number to load (zero based integer)
If hDib is zero loading has failed. */
hDib = BiTiff.LoadTiffFromMemory(hMemBlock, 0);
if (hDib == 0)
MessageBox.Show("Error loading DIB from the memory
block.", "Load TIFF Sample",
MessageBoxButtons.OK);