tif多页打印

void TifPrint(LPCTSTR lpPrinterName,LPCTSTR lpFilePath) 

{

// TODO: Add your control notification handler code here

   // Zero and then initialize the members of a DOCINFO structure. 

 

//

HDC hPrinterDC = NULL; /*printer dc*/

HDC hWinDC = NULL; /*windows dc*/

DOCINFO di = {0};

float fLogPelsX1, fLogPelsY1; /*windows log pixelsx*/

float fLogPelsX2, fLogPelsY2; /*print driver log pixelsx*/

float fScaleX, fScaleY;

int cWidthPels, cHeightPels;

 

//

    memset( &di, 0, sizeof(DOCINFO) );

    di.cbSize = sizeof(DOCINFO); 

    di.lpszDocName = "Tif Printing Test"; 

    di.lpszOutput = (LPTSTR) NULL; 

    //di.lpszDataType = (LPTSTR) NULL; 

    di.fwType = 0; 

 

hPrinterDC = CreateDC(NULL, lpPrinterName, NULL, NULL);

    // Begin a print job by calling the StartDoc function. 

 

    int nError = StartDoc(hPrinterDC, &di); 

 

    // Retrieve the number of pixels-per-logical-inch in the 

    // horizontal and vertical directions for the display upon which 

    // the bitmap was created. These are likely the same as for 

    // the present display, so we use those values here. 

 

hWinDC = CreateDC (TEXT("DISPLAY"), NULL, NULL, NULL);

    fLogPelsX1 = (float) GetDeviceCaps(hWinDC, LOGPIXELSX); 

    fLogPelsY1 = (float) GetDeviceCaps(hWinDC, LOGPIXELSY); 

 

    // Retrieve the number of pixels-per-logical-inch in the 

    // horizontal and vertical directions for the printer upon which 

    // the bitmap will be printed. 

 

    fLogPelsX2 = (float) GetDeviceCaps(hPrinterDC, LOGPIXELSX); 

    fLogPelsY2 = (float) GetDeviceCaps(hPrinterDC, LOGPIXELSY); 

 

    // Determine the scaling factors required to print the bitmap and 

    // retain its original proportions. 

 

fScaleX = fLogPelsX2/fLogPelsX1;//1.04167

fScaleY = fLogPelsY2/fLogPelsY1;//1.04167

 

//

USES_CONVERSION;

//

GdiplusStartupInput gdiplusStartupInput;

ULONG_PTR gdiplusToken;

GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

Image* image = new Image(A2W(lpFilePath));//(L"C://Microsoft Word - ecgprint阅读笔记.tif");//(L"Multiframe.tif");

// How many frame dimensions does the Image object have?

UINT count = 0;

count = image->GetFrameDimensionsCount();

//printf("The number of dimensions is %d./n", count);

GUID* pDimensionIDs = (GUID*)malloc(sizeof(GUID)*count);

// Get the list of frame dimensions from the Image object.

image->GetFrameDimensionsList(pDimensionIDs, count);

// Display the GUID of the first (and only) frame dimension.

WCHAR strGuid[39];

StringFromGUID2(pDimensionIDs[0], strGuid, 39);

// Get the number of frames in the first dimension.

UINT frameCount = image->GetFrameCount(&pDimensionIDs[0]);

 

//

    // Compute the coordinates of the upper left corner of the 

    // centered bitmap. 

 

//

int XDest = 0;

int YDest = 0;

int nDestWidth = 0;

int nDestHeight = 0;

cWidthPels = GetDeviceCaps(hPrinterDC, HORZRES);

cHeightPels = GetDeviceCaps(hPrinterDC, VERTRES);

nDestWidth = (int)(image->GetWidth()*fScaleX);

nDestHeight = (int)(image->GetHeight()*fScaleY);

if(nDestWidth > cWidthPels)

{

nDestWidth = cWidthPels;

}

else

{

XDest = ((cWidthPels / 2) - ((int) (((float) image->GetWidth()) * fScaleX)) / 2); 

}

if(nDestHeight > cHeightPels)

{

nDestHeight = cHeightPels;

}

else

{

YDest = ((cHeightPels / 2) - ((int) (((float) image->GetHeight()) * fScaleY)) / 2); 

}

 

//

UINT fIndex = 0;

while(fIndex < frameCount)

{

image->SelectActiveFrame(&pDimensionIDs[0],fIndex);//重新设置当前的活动数据帧

nError = StartPage(hPrinterDC); 

        Graphics graphics(hPrinterDC); //hDC是外部传入的画图DC

RectF destRect(XDest, YDest, nDestWidth, cHeightPels);

        graphics.DrawImage(image,destRect,0, 0, image->GetWidth(), image->GetHeight(), UnitPixel);

fIndex++;

nError = EndPage(hPrinterDC); 

}

//

free(pDimensionIDs);

delete(image);

GdiplusShutdown(gdiplusToken);

 

    // Inform the driver that document has ended. 

 

    nError = EndDoc(hPrinterDC);  

 

 

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值