I am having a heck of a time getting a GDI+ bitmap to print to a printer in Freebasic. I have been trying to adapt some of Jose's Powerbasic code but I am in over my head. Could anyone give me a pointer on the code below. I can get the bitmap to print to the screen OK (but only after hours of trial and error) but no luck on the printer. Thanks
FUNCTION EZP_DrawBitmap (BYVAL MyDC as hDC,BYVAL hbmp AS HBITMAP,MyAngle as single, BYVAL x AS SINGLE = 0, BYVAL y AS SINGLE = 0, _
BYVAL nRight AS SINGLE = 0, BYVAL nBottom AS SINGLE = 0, AspectFlag as integer = 0) AS GpStatus
DIM nStatus AS GpStatus, pGraphics AS GpGraphics PTR, pBitmap AS GpBitmap PTR
DIM nWidth AS DWORD, nHeight AS DWORD
DIM StartupInput AS GdiplusStartupInput
DIM token AS ULONG_PTR
Dim pixelColor As COLORREF
dim TempDC1 as hDC
dim TempDC2 as hDC
dim hbit as HBITMAP
dim xxx as LONG
Dim frameCount AS integer
DIM pageGuid AS GUID => ( &H86DC6274, &H8061, &H7E4C, {&H8E ,&H3F, &HEE, &H73, &H33, &HA7, &HA4, &H8 })
Dim nCount AS LONG
'$FrameDimensionPage = GUID$("{7462DC86-6180-4C7E-8E3F-EE7333A7A483}")
' // Initialize GDI+
StartupInput.GdiplusVersion = 1
GdiplusStartup(@token, @StartupInput, NULL)
DO
nStatus = GdipCreateBitmapFromHBITMAP (hbmp, NULL, @pBitmap)
IF pBitmap = NULL THEN EXIT DO
GdipGetImageWidth(cast(GpImage PTR, pBitmap), @nWidth)
GdipGetImageHeight(cast(GpImage PTR, pBitmap), @nHeight)
'Full Picture
if nRight = 0 and nBottom = 0 THEN
nRight = nWidth
nBottom = nHeight
end if
if AspectFlag <> 0 THEN
if nRight = 0 and nBottom = 0 THEN
'Nothing for now
else
nBottom = nBottom *(nHeight/nWidth)
end if
end if
MyAngle = MyAngle + 180
GdipImageRotateFlip(cast(any ptr,pBitmap),6)
nStatus = GdipCreateFromHDC(MyDC, @pGraphics)
if EZP.SorP = 1 THEN
nStatus = GdipImageGetFrameDimensionsCount(cast(any ptr,pBitmap), @nCount)
IF nCount THEN
' // Get the list of frame dimensions from the Image object.
REDIM dimensionIDs(nCount - 1) AS GUID
nStatus = GdipImageGetFrameDimensionsList(cast(any ptr,pBitmap), @dimensionIDs(0), nCount)
' // Get the number of frames in the first (and only) frame dimension.
nStatus = GdipImageGetFrameCount(cast(any ptr,pBitmap), @dimensionIDs(0), @frameCount)
IF frameCount = 0 THEN GOTO LExit
END IF
END IF
IF nStatus <> S_OK OR pGraphics = 0 THEN Print "Problem with Graphic DC"
nStatus = GdipBitmapGetPixel(pBitmap, 1, 1, @pixelColor)
IF pGraphics = NULL THEN EXIT DO
GdipSetSmoothingMode(pGraphics, SmoothingModeAntiAlias)
GdipSetInterpolationMode(pGraphics, InterpolationModeHighQualityBicubic)
GdipRotateWorldTransform(pGraphics,MyAngle,MatrixOrderAppend)
GdipTranslateWorldTransform(pGraphics,x+(nRight/2), y +(nBottom/2),MatrixOrderAppend)
if EZP.SorP = 0 THEN
GdipDrawImageRectI(pGraphics,cast(any ptr, pBitmap),nRight/2,nBottom/2,-nRight,-nBottom)
else
FOR xxx = 0 TO frameCount - 1
nStatus = GdipImageSelectActiveFrame(cast(any ptr, pBitmap), @pageGuid, xxx)
GdipDrawImageRectI(pGraphics,cast(any ptr, pBitmap),nRight/2,nBottom/2,-nRight,-nBottom)
next xxx
end if
GdipResetWorldTransform(pGraphics)
EXIT DO
LOOP
LExit:
IF pBitmap THEN GdipDisposeImage(cast(GpImage PTR, pBitmap))
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
' // Shutdown GDI+
GdiplusShutdown token
RETURN nStatus
END FUNCTION