#include "Winspool.h"
#include <atlconv.h>
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment (lib, "Gdiplus.lib")
BOOL PrintImageUsingGDIPlus( char* szPath, char* szPrn )
{
DEVMODE *pDM;
LONG dmLen;
HANDLE prnHandle;
HDC hDC;
UINT dimCount, frameCount;
GUID *pDimIDs;
GUID pageGuid;
float width, height;
DOCINFO di = { sizeof(DOCINFO), "Printing My Image" };
if( !OpenPrinter( szPrn, &prnHandle, 0 ) )
return 0;
dmLen = DocumentProperties( 0, prnHandle, szPrn, 0, 0, 0 );
pDM = (DEVMODE*)new char[dmLen];
DocumentProperties( 0, prnHandle, szPrn, pDM, 0, DM_OUT_BUFFER );
hDC = CreateDC( szPrn, szPrn, 0, pDM );
delete pDM;
if( !hDC )
{
ClosePrinter( prnHandle );
return 0;
}
if( StartDoc( hDC, &di ) == SP_ERROR )
{
ClosePrinter( prnHandle );
return 0;
}
Graphics graphics( hDC );
USES_CONVERSION;
Image image( A2W( szPath ) );
dimCount = image.GetFrameDimensionsCount();
pDimIDs = new GUID[dimCount];
image.GetFrameDimensionsList( pDimIDs, dimCount );
frameCount = image.GetFrameCount( &pDimIDs[0] );
delete pDimIDs;
pageGuid = FrameDimensionPage;
for( UINT i = 0; i < frameCount; i++ )
{
StartPage( hDC );
image.SelectActiveFrame( &pageGuid, i );
graphics.SetPageUnit( UnitInch );
width = image.GetWidth() / image.GetHorizontalResolution();
height = image.GetHeight() / image.GetVerticalResolution();
graphics.DrawImage( &image, 0.f, 0.f, width, height );
EndPage( hDC );
}
EndDoc( hDC );
ClosePrinter( prnHandle );
return ( frameCount > 0 ) ? TRUE : FALSE;
}
|