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("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("Error opening TIFF in the
memory.", MB_OK|MB_ICONERROR);
GlobalFree(hMemBlock);
[VB]
‘Use LoadTiffFromMemory from BiTiff.ocx
Dim hDib as Long
Dim BITiffobj As Object
' Create DIB from the handle
Set BITiffobj = CreateObject("BITIFF.BITiffCtrl.1")
‘ 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 = BITiffobj.LoadTiffFromMemory(hMemBlock, 0)
Set BITiffobj = Nothing
If Dib > 0 Then
MsgBox "Error loading DIB from the memory block.", _
vbOKOnly + vbExclamation
End If
[C#]
/* Use LoadTiffFromMemory from BiTiff.ocx */
int hDib;
/* 1. parameter: Handle of the memory block (int)
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);