Function gPrnSayImage( oPrn, nRow, nCol, oImage, nWidth, nHeight, nRaster, lStretch, nAlphaLevel, nAlign )
local hDib, hPalBmp, hPal, nRatio, n, cImageBuf, lCreated := .f.
local hBmp, x, y
local ogbmp , cFile
DEFAULT nWidth := 0, nHeight := 0, lStretch := .t., nAlphaLevel := 255, nAlign := 1 // center
if oPrn:hDC = 0
return nil
endif
if ValType( oImage ) == 'C'
if File( oImage )
cFile:= oImage
// oImage := TImage():Define( , oImage )
oImage := TImage():Define( )
oGBmp:= GDIBmp():new(cFile)
oImage:hbitmap := oGBmp:GetGDIHbitmap()
oImage:HasAlpha()
oImage:refresh()
//oGbmp:end()
lCreated := .t.
else
cImageBuf := oImage
oImage := TImage():Define()
oGBmp:= GDIBmp():new()
oGBmp:LoadFromStr( cImageBuf )
oImage:hbitmap := oGBmp:GetGDIHbitmap()
oImage:HasAlpha()
oImage:refresh()
//oGbmp:end()
// oImage:LoadFromMemory( cImageBuf )
lCreated := .t.
endif
endif
do case
case ValType( oImage ) == "O"
hDib = DibFromBitmap( oImage:hBitmap, oImage:hPalette )
otherwise
hDib = 0
endcase
if hDib = 0
return nil
endif
if ! oPrn:lMeta
hPal := DibPalette( hDib )
endif
x := nWidth; y := nHeight
// try to keep aspect ratio if only one size is passed in.
if nWidth == 0 .and. nHeight > 0 .and. ( n := oImage:nHeight() ) > 0
nRatio := oImage:nWidth() / n
x := int( nHeight * nRatio )
elseif nWidth > 0 .and. nHeight == 0 .and. ( n := oImage:nWidth() ) > 0
nRatio := oImage:nHeight() / n
y := int( nWidth * nRatio )
elseif nWidth > 0 .and. nHeight > 0 .and. ! lStretch
if ( nWidth / oImage:nWidth() ) < ( nHeight / oImage:nHeight() )
x := nWidth; y := oImage:nHeight() * ( nWidth / oImage:nWidth() )
else
y := nHeight; x := oImage:nWidth() * ( nHeight / oImage:nHeight() )
endif
if x < nWidth
if lAnd( nAlign, 1 ) // DT_CENTER = 1
nCol += Int( ( nWidth - x ) / 2 )
elseif lAnd( nAlign, 2 ) // DT_RIGHT = 2
nCol += ( nWidth - x )
endif
endif
if y < nWidth
if lAnd( nAlign, 4 ) // DT_VCENTER = 4
nRow += Int( ( nHeight - y ) / 2 )
elseif lAnd( nAlign, 8 ) // DT_BOTTOM = 8
nRow += ( nHeight - y )
endif
endif
endif
if oImage:HasAlpha()
hBmp := ResizeBmp( oImage:hBitmap, x, y )
ABPaint( oprn:hDCOut, nCol, nRow, hBmp, nAlphaLevel )
DeleteObject( hBmp )
else
DibDraw( oprn:hDCOut, hDib, hPal, nRow, nCol, x, y, nRaster )
endif
GlobalFree( hDib )
if ! oprn:lMeta
DeleteObject( hPal )
endif
if lCreated
oImage:End()
endif
return nil
//----------------------------------------------------------------------------//