If you have annotation objects on the image, you can print them. There are two ways to do it:
Burn annotation objects to the page, and print the page. See Single and Multipage Printing section.
You can print annotation objects without burning.
[C++]
/* Print an image and annotations */
#include “BiPrint.h”
void CMyDoc::MyPrint()
{
GPRINT sPrint;
DWORD nPageCnt;
// Set printig properties
sPrint.bDisplay = 1;
sPrint.bCenterVertImg = 0;
sPrint.bCenterHorizImg = 0;
sPrint.bScalePage = 1;
sPrint.bUseDPI = 1;
sPrint.nNumCopies = 1;
sPrint.bConvertCtoB = 0;
sPrint.bStretchPage = 0;
sPrint.bAllPage = 1;
// Prepares to print
// 1. parameter (HWND): Handle to the window
// 2. parameter (HDC): Printer DC. Can be NULL.
// 3. parameter (LPGPRINT): Pointer to the print information structure
// 4. parameter (LPTSTR): Name of the file to print
// 5. parameter (UINT): Number of pages in the document
int ret = PrepareToPrint(AfxGetMainWnd()->m_hWnd, App->m_PrinterDC
,&sPrint, szFileName, nImages);
POINT ptDPI;
LPPOINT lpPointDPI = NULL;
LPBITMAPINFOHEADER lpbmi =
(LPBITMAPINFOHEADER)GlobalLock(hDib);
if(lpbmi->biXPelsPerMeter && lpbmi->biYPelsPerMeter)
{
ptDPI.x = (int)( (float)lpbmi->biXPelsPerMeter / 39.37 + 0.5 );
ptDPI.y = (int)( (float)lpbmi->biYPelsPerMeter / 39.37 + 0.5 );
lpPointDPI = &ptDPI;
}
GlobalUnlock(hDib);
if (!ret)
{
HBITMAP hBmp = ConvertDIBToBitmap(hDib);
if(hBmp)
{
HDC hDC1 = CreateDC(_T("DISPLAY"),NULL,NULL,NULL);
if (hDC1)
{
HDC hDC = CreateCompatibleDC( hDC1 ); if (hDC)
{
HGDIOBJ hOld;
hOld = SelectObject( hDC, hBmp );
AnnoObjDeselect(lAnno, NULL);;
AnnoUIOnPaint( lAnno, hDC );
SelectObject(hDC,hOld);
HDIB hDb = ConvertBitmapToDIB(hBmp, NULL);
if(hDb)
{
// Copy DPI value from hDib to hDb
CopyDibDPI( hDb, hDib );
// 1. parameter: Handle of the DIB
// 2. parameter: Image DPI
// 3. parameter: Scaling factor
// 4. parameter: Current Page number
// 5. parameter: A positive absolute offset in pixel
// on the X
// coordinate on the page to start printing.
// 6. parameter: A positive absolute offset in pixel
// on the Y
// coordinate on the page to start printing.
PrintDIBPage(hDb, lpPointDPI,
&rScale,nCurPage,0,0);
GlobalFree( hDb );
}
DeleteDC( hDC );
}
DeleteDC( hDC1 );
}
DeleteObject(hBmp);
}
}
EndPrint(NULL);
}
[C#]
// Burn annotation objects
…
// Print DIB
private void Print()
{
long hDib = BiDisp.hDib;
long hwnd = BiDisp.hWnd;
int[] sRect;
sRect = new int[4];
sRect[0] = 1;
sRect[1] = 1;
sRect[2] = 1;
sRect[3] = 1;
if (PrinterSettings.InstalledPrinters.Count > 0)
{
// Print the actual DIB
if (hDib != 0)
{
// 1. parameter: Window handle for dialog boxes
// 2. parameter: Capture text to print
// 3. parameter: maximum page number
// 4. parameter: Number of copies
// 5. parameter: Display print dialog box
// 6. parameter: Center image vertically
// 7. parameter: Center image horizontally
// 8. parameter: Scale image to fit proportionally
// 9. parameter: Convert bitmap to monochrome
// 10. parameter: Stretch bitmap
// 11. parameter: All pages
// 12. parameter: Use DPI settings
// 13. parameter: Display or not cancel printing dialog box
BiPrint.PrepareToPrint(hwnd, GetDocument().szFileName,
maxPage, 1, true, false, false, false, false, false, false, true, false);
BiPrint.PrintDIBPage(hDib, ref sRect[0], 1, 0, 0);
BiPrint.EndPrint();
}
}
else
{
// Error
}
}