打印的CDC在纸上看起来很小 [英] Printed CDC appears tiny on paper

查看:109
本文介绍了打印的CDC在纸上看起来很小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我为自己创建的报告控件打印CDC时,它看起来很小(纸上小于1平方英寸).如何获得要打印的报告以占据整个页面? 换句话说,如何使整个报告显示在一个打印的页面中.

CPrintDialog printDialog(FALSE); printDialog.DoModal();

m_CDC是我用来缓冲并在屏幕上显示整个报告的内存DC.

解决方案

正如其他人所说,这是因为一般而言,打印机的显示分辨率比显示器高很多.显示器通常为96到120DPI:在96DPI时,这意味着96像素(点)乘96像素的图像在显示器上占据大约1平方英寸.但是,如果仅拍摄该图像并在600DPI打印机上将其打印出来,则图像的大小约为1/6英寸乘1/6英寸-会小得多.这是出版界的祸根-在显示器上看起来很好的图像在打印时通常看起来很小或很糟糕.

如建议的那样,您可以使用StretchBlt而不是BitBlt来放大图像.视显示器和打印机的不同而定,它看起来可能有点块状,或者完全是丑陋的块状.

一个更好的选择是重写代码来绘制控件,以便您获得一个使用设备上下文(和一些坐标)并绘制到其中的方法.您的常规窗口绘画代码可以将内存DC传递给该例程,然后将结果BitBlt传递给窗口,并且您的绘画代码可以使用打印机DC和一些合适的坐标来调用此方法.

编写此例程时,您将不得不担心缩放问题:例如,您需要为给定的设备上下文创建字体,并且使用缩放比例独立的大小(即,以磅为单位指定字体大小,而不是像素),而不是依赖于预先创建的字体.

When I print the CDC for a report control that I've created it appears tiny (less than 1 square inch on paper). How can I get the report to be printed to occupy the entire page ? Or in other words, how can I make the entire report to appear in one printed page.

CPrintDialog printDialog(FALSE); printDialog.DoModal();

CDC dcPrint;
if(dcPrint.Attach(printDialog.GetPrinterDC()))
{
    int iHorzRes = dcPrint.GetDeviceCaps(HORZRES);
    int iVertRes = dcPrint.GetDeviceCaps(VERTRES);

    int iHorzResCDC = m_CDC.GetDeviceCaps(HORZRES);
    int iVertResCDC = m_CDC.GetDeviceCaps(VERTRES);

    dcPrint.m_bPrinting = TRUE;
            dcPrint.BitBlt(0,0, iHorzRes, iVertRes, &m_CDC, iHorzResCDC, iVertResCDC, SRCCOPY);
    CFont* pOldFont = dcPrint.SelectObject(&m_HeaderFont);
    dcPrint.TextOut(0,0,"HelloWorld")       ;
    dcPrint.SelectObject(pOldFont);

    CPrintInfo printInfo;
    printInfo.m_rectDraw.SetRect(0,0, iHorzRes, iVertRes);
    dcPrint.StartDoc("Report Print");       
    dcPrint.StartPage();
    if(dcPrint.EndPage())
        dcPrint.EndDoc();
    else
        dcPrint.AbortDoc();     
}

dcPrint.DeleteDC();

m_CDC is the memory DC that I use to buffer and display the entire report on screen.

解决方案

As others have said, this is because, in general, the display resolution of printers is a lot higher than displays. Displays are usually 96 to 120DPI: at 96DPI this means that an image of 96 pixels (dots) by 96 pixels occupies approximately 1 square inch on the display. However, if you just take that image and print it out on a 600DPI printer, the size of the image will be about 1/6" by 1/6" - much smaller. This is a bane of the publishing world - images that look fine on displays often look either tiny or terrible when printed.

You could, as has been suggested, use StretchBlt rather than BitBlt to scale up your image. Depending on the difference between your display and printer, this will either look a bit blocky, or utterly hideously blocky.

A much better option is to rewrite your code that does the drawing of the control so that you've got a method that takes a device context (and some co-ordinates) and draws into it. Your normal window painting code can pass the memory DC to this routine and then BitBlt the result to the window, and your painting code can call this method with the printer DC and some suitable co-ordinates.

When writing this routine you'll have to worry about scaling: for example, you'll need to create fonts for the given device context, and with a scaling-indepdendant size (that is, specify the font size in points, not pixels), rather than relying on a pre-created font.

这篇关于打印的CDC在纸上看起来很小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆