none
D2d 打印问题 RRS feed

  • 问题

  • 依据Direct2D printing images and effectssample示例实现pdf文件的打印功能:

    程序先将页面绘制成图片放在内存中,然后将图片转换为wicBitmap,由DrawBitmap绘制到ComPtr<ID2D1DeviceContext> 中,最后用PrintControl的AddPage将页面添加到打印机。 这里有几个疑问:

    1. AddPage之后是否打印机已经开始打印该图片?

    2.因为要打印多页,打印完一页图片之后是否能 捕获到打印机送回的消息?

    3.目前这种Addpage会造成打印池的缓冲占用巨大,而且要等到 PrintControl Close后才会开始真正的打印,能否让他直接就开始打印?

    在打印55页的文件的时候,打印缓冲会有5G之多! 并且打印机并没开始打印。

    void PageRenderer::PrintPage( _In_ uint32 pageNumber, _In_ D2D1_RECT_F imageableArea, _In_ D2D1_SIZE_F pageSize, _In_opt_ IStream* pagePrintTicketStream ) { // Create a new D2D device context for generating the print command list. // D2D device contexts are stateful, and hence a unique device context must // be used on each thread. ComPtr<ID2D1DeviceContext> d2dContext; DX::ThrowIfFailed( m_d2dDevice->CreateDeviceContext( D2D1_DEVICE_CONTEXT_OPTIONS_NONE, &d2dContext ) ); ComPtr<ID2D1CommandList> printCommandList; DX::ThrowIfFailed( d2dContext->CreateCommandList(&printCommandList) ); //获得打印纸张大小,由DIP转换为DPI d2dContext->SetTarget(printCommandList.Get()); double width = pageSize.width * m_printControlProperties.rasterDPI/96; double height = pageSize.height * m_printControlProperties.rasterDPI/96; for(int page=0 ;page <pageCount; page++) { double RenderWidth = width; double RenderHeight = height/nBlockCount; //将页面绘制在图片pageBitmap_print上 DrawPrintPageBitmap(pageNumber-1,width,height,nBlockWidthIndex,nBlockHeightIndex,nBlockCount); void* PageBuffer = Bitmap_GetBuffer(pageBitmap_print); int nHeight = FS_Bitmap_GetHeight(pageBitmap_print)); int nWidth = FS_Bitmap_GetWidth(pageBitmap_print); int nBufSize = FS_Bitmap_GetStride((pageBitmap_print)) * FS_Bitmap_GetHeight((pageBitmap_print)); ComPtr<ID2D1Bitmap1> bitmap1; D2D1_SIZE_U pixelSize = D2D1::SizeU( nWidth, nHeight ); DX::ThrowIfFailed( d2dContext->CreateBitmap( pixelSize, PageBuffer, // 位图数据 pixelSize.width * 4, // pitch = width * size of pixel (4 bytes for B8G8R8A8) D2D1::BitmapProperties1( D2D1_BITMAP_OPTIONS_NONE, D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED)), &bitmap1 )); d2dContext->BeginDraw(); D2D1_RECT_F rc = D2D1::RectF(0, 0,pageSize.width,pageSize.height); d2dContext->DrawBitmap(bitmap1.Get(),rc); //绘制图片到打印dc上 DX::ThrowIfFailed( d2dContext->EndDraw() ); DX::ThrowIfFailed( printCommandList->Close() ); DX::ThrowIfFailed( m_d2dPrintControl->AddPage(printCommandList.Get(), pageSize, pagePrintTicketStream)

    //此处add之后就开始打印了吗? );

    }

    m_d2dPrintControl->Close();

    }




    • 已编辑 WillSu 2012年12月10日 11:12
    2012年12月10日 11:10

全部回复