// GdiPlus support (c) FiveTech Software
#include <hbapi.h>
#include <windows.h>
#include <gdiplus.h>
using namespace Gdiplus;
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
//----------------------------------------------------------------------------//
HB_FUNC( GDIPLUSNEWGRAPHICS )
{
hb_retnl( ( HB_LONG ) new Graphics( ( HDC ) hb_parnl( 1 ) ) );
}
//----------------------------------------------------------------------------//
HB_FUNC( GDIPLUSDELETEGRAPHICS )
{
delete ( ( Graphics * ) hb_parnl( 1 ) );
}
//----------------------------------------------------------------------------//
HB_FUNC( GDIPLUSHIGHQUALITY )
{
Graphics * graphics = ( Graphics * ) hb_parnl( 1 );
graphics->SetSmoothingMode( SmoothingModeHighQuality );
}
//----------------------------------------------------------------------------//
HB_FUNC( GDIPLUSNORMALQUALITY )
{
Graphics * graphics = ( Graphics * ) hb_parnl( 1 );
graphics->SetSmoothingMode( SmoothingModeDefault );
}
//----------------------------------------------------------------------------//
HB_FUNC( GDIPLUSNEWPEN )
{
Color clr = Color( hb_parnl( 1 ), hb_parnl( 2 ), hb_parnl( 3 ), hb_parnl( 4 ) );
hb_retnl( ( HB_LONG ) new Pen( clr ) );
}
//----------------------------------------------------------------------------//
HB_FUNC( GDIPLUSPENSIZE )
{
Pen * pen = ( Pen * ) hb_parnl( 1 );
pen->SetWidth( hb_parnl( 2 ) );
}
//----------------------------------------------------------------------------//
HB_FUNC( GDIPLUSPENSTYLE )
{
Pen * pen = ( Pen * ) hb_parnl( 1 );
pen->SetLineCap( ( LineCap ) hb_parnl( 2 ), ( LineCap ) hb_parnl( 2 ),
( DashCap ) hb_parnl( 2 ) );
}
//----------------------------------------------------------------------------//
HB_FUNC( GDIPLUSALIGN )
{
Pen * pen = ( Pen * ) hb_parnl( 1 );
pen->SetAlignment(PenAlignmentInset);
}
//----------------------------------------------------------------------------//
HB_FUNC( GDIPLUSNOALIGN )
{
Pen * pen = ( Pen * ) hb_parnl( 1 );
pen->SetAlignment(PenAlignmentCenter);
}
//----------------------------------------------------------------------------//
HB_FUNC( GDIPLUSDELETEPEN )
{
delete ( ( Pen * ) hb_parnl( 1 ) );
}
//----------------------------------------------------------------------------//
HB_FUNC( GDIPLUSNEWSOLIDBRUSH )
{
Color clr = Color( hb_parnl( 1 ), hb_parnl( 2 ), hb_parnl( 3 ), hb_parnl( 4 ) );
hb_retnl( ( HB_LONG ) new SolidBrush( clr ) );
}
//----------------------------------------------------------------------------//
HB_FUNC( GDIPLUSDELETEBRUSH )
{
delete ( ( Brush * ) hb_parnl( 1 ) );
}
//----------------------------------------------------------------------------//
HB_FUNC( GDIPLUSDRAWLINE )
{
Graphics * graphics = ( Graphics * ) hb_parnl( 1 );
if HB_ISNUM( 2 ) // if pen-object
{
Pen * pen = ( Pen * ) hb_parnl( 2 );
graphics->DrawLine( pen, ( float ) hb_parnd( 3 ),
( float ) hb_parnd( 4 ), ( float ) hb_parnd( 5 ),
( float ) hb_parnd( 6 ) );
}
}
//----------------------------------------------------------------------------//
HB_FUNC( GDIPLUSDRAWRECT )
{
Graphics * graphics = ( Graphics * ) hb_parnl( 1 );
Pen * pen = ( Pen * ) hb_parnl( 2 );
float nLeft = hb_parnd( 4 );
float nTop = hb_parnd( 5 );
float nWidth = hb_parnd( 6 );
float nHeight = hb_parnd( 7 );
if HB_ISNUM( 3 ) // if brush-object
{
Brush * brush = ( Brush * ) hb_parnl( 3 );
graphics->FillRectangle( brush, nLeft, nTop, nWidth, nHeight );
}
if HB_ISNUM( 2 ) //if pen-object
{
Pen * pen = ( Pen * ) hb_parnl( 2 );
graphics->DrawRectangle( pen, nLeft, nTop, nWidth, nHeight );
}
}
//----------------------------------------------------------------------------//
HB_FUNC( GDIPLUSDRAWELLIPSE )
{
Graphics * graphics = ( Graphics * ) hb_parnl( 1 );
Pen * pen = ( Pen * ) hb_parnl( 2 );
float nLeft = hb_parnd( 4 );
float nTop = hb_parnd( 5 );
float nWidth = hb_parnd( 6 );
float nHeight = hb_parnd( 7 );
if HB_ISNUM( 3 ) //if brush-object
{
Brush * brush = ( Brush * ) hb_parnl( 3 );
graphics->FillEllipse( brush, nLeft, nTop, nWidth, nHeight );
}
if HB_ISNUM( 2 ) //if pen-object
{
Pen * pen = ( Pen * ) hb_parnl( 2 );
graphics->DrawEllipse( pen, nLeft, nTop, nWidth, nHeight );
}
}
//----------------------------------------------------------------------------//
HB_FUNC( GDIPLUSSTARTUP )
{
hb_retl( GdiplusStartup( &gdiplusToken, &gdiplusStartupInput, NULL ) );
}
//----------------------------------------------------------------------------//
HB_FUNC( GDIPLUSSHUTDOWN )
{
GdiplusShutdown( gdiplusToken );
}
//----------------------------------------------------------------------------//
HB_FUNC( SETPAGEUNIT2PIXEL )
{
Graphics * graphics = ( Graphics * ) hb_parnl( 1 );
graphics->SetPageUnit( UnitPixel ); // Unit to Pixel
}
//----------------------------------------------------------------------------//
HB_FUNC( GDIPLUSDRAWARC )
{
Graphics * graphics = ( Graphics * ) hb_parnl( 1 );
Pen * pen = ( Pen * ) hb_parnl( 2 );
float nLeft = hb_parnd( 3 );
float nTop = hb_parnd( 4 );
float nWidth = hb_parnd( 5 );
float nHeight = hb_parnd( 6 );
float startAngle = hb_parnd( 7 );
float sweepAngle = hb_parnd( 8 );
graphics->DrawArc( pen, nLeft, nTop, nWidth, nHeight, startAngle, sweepAngle);
}
//----------------------------------------------------------------------------//
HB_FUNC( GDIPLUSCREATEPATH )
{
hb_retnl( ( HB_LONG ) new GraphicsPath() );
}
//----------------------------------------------------------------------------//
HB_FUNC( GDIPLUSDELETEPATH )
{
delete ( ( GraphicsPath * ) hb_parnl( 1 ) );
}
//----------------------------------------------------------------------------//
HB_FUNC( GDIPLUSPATHADDLINE )
{
GraphicsPath * graphicPath = ( GraphicsPath * ) hb_parnl( 1 );
float nLeft = hb_parnd( 2 );
float nTop = hb_parnd( 3 );
float nRight = hb_parnd( 4 );
float nBottom = hb_parnd( 5 );
graphicPath->AddLine( nLeft, nTop, nRight, nBottom ) ;
}
//----------------------------------------------------------------------------//
HB_FUNC( GDIPLUSDRAWPATH )
{
Graphics * graphics = ( Graphics * ) hb_parnl( 1 );
Pen * pen = ( Pen * ) hb_parnl( 2 );
GraphicsPath * graphicPath = ( GraphicsPath * ) hb_parnl( 3 );
graphics->DrawPath( pen, graphicPath );
}
HB_FUNC( GDIPLUSPENSETCLR )
{
Pen * pen = ( Pen * ) hb_parnl( 1 );
Color clr = Color( hb_parnl( 2 ), hb_parnl( 3 ), hb_parnl( 4 ), hb_parnl( 5 ) );
hb_retni( pen->SetColor( clr ) );
}
CLASS Graphics
....
METHOD DrawArc( oPen, nLeft, nTop, nWidth, nHight,startAngle, sweepAngle ) INLINE ;
GdiPlusDrawArc( oPen:hPen, nLeft, nTop, nWidth, nHeight, startAngle, sweepAngle )
METHOD DrawPath( oPen, oPath ) INLINE GdiPlusDrawPath( oPen:hPen, oPath:hPath )
.....
CLASS Pen
...
METHOD SetColor( nTrans, nRed, nGreen, nBlue ) INLINE ;
GdiPlusPenSetClr( ::hPen, nTrans, nRed, nGreen, nBlue ) // nuevo methodo clase pen
.....
CLASS Path / nueva clase Path
DATA hPath
METHOD New()
METHOD Destroy()
METHOD AddLINE ( nLeft, nTop, nRight, nBottom ) INLINE GdiPlusPathAddLine( ::hPath, nLeft, nTop, nRight, nBottom )
DESTRUCTOR Destroy()
ENDCLASS
//----------------------------------------------------------------------------//
METHOD New() CLASS Path
::hPath = GdiPlusCreatePath()
return Self
//----------------------------------------------------------------------------//
METHOD Destroy() CLASS Path
GdiPlusDeletePath( ::hPath )
::hBrush = nil
return nil
HB_FUNC( GDIPLUSCREATEIMAGEFROMFILE )
{
Image * newImage = new Image( (LPCWSTR) hb_parc(1) );
hb_retnl( ( HB_LONG ) newImage );
}
//----------------------------------------------------------------------------//
HB_FUNC( GDIPLUSDRAWIMAGE )
{
int iParams = hb_pcount();
Graphics * graphics = ( Graphics * ) hb_parnl( 1 );
Image * newImage = ( Image * ) hb_parnl( 2 );
int nLeft ;
int nTop ;
int nWidth ;
int nHeight;
switch (iParams){
case 4:
nLeft = hb_parni( 3 );
nTop = hb_parni( 4 );
graphics->DrawImage( newImage, nLeft, nTop );
case 6:
nLeft = hb_parni( 3 );
nTop = hb_parni( 4 );
nWidth = hb_parni( 5 );
nHeight = hb_parni( 6 );
graphics->DrawImage( newImage, nLeft, nTop,nWidth,nHeight);
}
}
//----------------------------------------------------------------------------//
HB_FUNC( GDIPLUSIMAGESAVE )
{
Image * newImage = ( Image * ) hb_parnl( 1 );
CLSID cClsid ;
LPWSTR file = (LPWSTR) hb_parc(2);
LPWSTR identificador = (LPWSTR) hb_parc(3);
CLSIDFromString( identificador, &cClsid ) ;
newImage->Save( file , &cClsid, NULL);
}
//----------------------------------------------------------------------------//
METHOD DrawImage( oImage,nTop,nleft, nWidth, nHeight ) CLASS Graphics
if Empty(nWidth ) .or. Empty( nHeight )
GdiPlusDrawImage( ::hGraphics, oImage:hImage, nTop, nLeft )
else
GdiPlusDrawImage( ::hGraphics, oImage:hImage,nTop,nLeft, nWidth, nHeight )
endif
Return nil
//----------------------------------------------------------------------------//
HB_FUNC( GDIPLUSIMAGEFINALIZE )
{
Image * newImage = ( Image * ) hb_parnl( 1 );
newImage.Finalize();
}
...........
//----------------------------------------------------------------------------//
CLASS GDIImage
DATA hImage
DATA aCLSID
DATa aExtensions
METHOD New(cFile)
METHOD Destroy()
METHOD Save( cFile )
DESTRUCTOR Destroy()
ENDCLASS
//----------------------------------------------------------------------------//
METHOD New( cFile ) CLASS GDImage
::hImage = GdiPlusCreateImageFromFile( AnsiToWide( cFile ) )
::aExtIni := { "BMP", "JPG", "GIF", "TIF", "PNG" }
::aExtEnd := { "BMP", "JPG", "GIF", "TIF", "PNG" }
::aCLSID := { "{557CF400-1A04-11D3-9A73-0000F81EF32E}" ,;
"{557CF401-1A04-11D3-9A73-0000F81EF32E}" ,;
"{557CF402-1A04-11D3-9A73-0000F81EF32E}" ,;
"{557CF405-1A04-11D3-9A73-0000F81EF32E}" ,;
"{557CF406-1A04-11D3-9A73-0000F81EF32E}" ;
}
return Self
//----------------------------------------------------------------------------//
METHOD Save( cFile ) CLASS GDIImage
local cExtension := Upper(cFileExt(cFile))
local cCLSID
local nScan:= aScan( ::aExtEnd, cFile )
if nScan == 0
msginfo( "Formato no soportado" )
Return .f.
endif
cCLSID := aCLSID[ nScan ]
cCLSID = AnsiToWide( cCLSID )
cFile = AnsiToWide( cFile )
GdiPlusImageSave( ::hImage, cFile, cCLSID )
Return nil
//----------------------------------------------------------------------------//
METHOD Destroy() CLASS GDIImage
GdiPlusImageFinalize( ::hImage )
::hImage = nil
return nil
//----------------------------------------------------------------------------//
Function GDIPlusConvertImage( cImageIni, cImageEnd )
local cExtIni := Upper(cFileExt( cImageIni ))
local cExtEnd := Upper(cFileExt( cImageEnd ))
local oImage
local nScan
if cImageIni == cImageEnd
msginfo( "Error. La imagen inicial y final son la misma" )
Return .f.
endif
if( nScan:= aScan( oImage:aExtIni, cExtIni )) == 0
Msginfo( " el archivo "+ cImageIni + " tiene un formato no soportado")
return .f.
endif
if( nScan:= aScan( oImage:aExtEnd, cExtEnd )) == 0
Msginfo( " el archivo "+ cImageEnd + " tiene un formato no soportado")
return .f.
endif
oImage:= GDIImage():New( cImageIni )
oImage:Save( cImageEnd )
oImage:Destroy()
Return nil
#include "FiveWin.ch"
function Main()
local hBmp
MsgInfo( GdiPLoadImageFromFile( "..\bitmaps\five.bmp", @hBmp ) )
MsgInfo( hBmp )
return nil
DLL FUNCTION GdipLoadImageFromFile( cFileName AS LPSTR, hImage AS LONG ) AS LONG PASCAL ;
LIB "GdiPlus.dll"
#include "FiveWin.ch"
function Main()
local hBmp := 0
MsgInfo( GdiPLoadImageFromFile( AnsiToWide( "..\bitmaps\five.bmp" ), @hBmp ) )
MsgInfo( hBmp )
return nil
DLL FUNCTION GdipLoadImageFromFile( cFileName AS LPSTR, hImage AS LONG ) AS LONG PASCAL ;
LIB "GdiPlus.dll"
#include "FiveWin.ch"
function Main()
local oGraphics := Graphics():New( 0 )
local hBmp := 0
MsgInfo( GdiPLoadImageFromFile( AnsiToWide( "..\bitmaps\five.bmp" ), @hBmp ) )
MsgInfo( hBmp )
return nil
DLL FUNCTION GdipLoadImageFromFile( cFileName AS LPSTR, hImage AS LONG ) AS LONG PASCAL ;
LIB "GdiPlus.dll"
Function GDIPlusConvertImage( cImageIni, cImageEnd )
local cExtIni := Upper(cFileExt( cImageIni ))
local cExtEnd := Upper(cFileExt( cImageEnd ))
local oImage
local nScan
if cImageIni == cImageEnd
msginfo( "Error. La imagen inicial y final son la misma" )
Return .f.
endif
oImage = GDIImage()-New( cImageIni )
if( nScan:= aScan( oImage:aExtIni, cExtIni )) == 0
Msginfo( " el archivo "+ cImageIni + " tiene un formato no soportado")
return .f.
endif
if( nScan:= aScan( oImage:aExtEnd, cExtEnd )) == 0
Msginfo( " el archivo "+ cImageEnd + " tiene un formato no soportado")
return .f.
endif
oImage:Save( cImageEnd )
oImage:Destroy()
Return nil
Return to FiveWin para Harbour/xHarbour
Users browsing this forum: Google [Bot] and 74 guests