#include "Fivewin.ch"
#include "Image.ch"
STATIC nImgW, nImgH
FUNCTION MAIN()
LOCAL oDlg, hDC, oImg, hPen, nStart := 0, lPaint := .F., aPoints[1][2]
LOCAL cWorkfile, cDestfile, nPenColor, nPenSize, nResize,cExtension
c_path := cFilePath(GetModuleFileName( GetInstance() ) )
c_path1 := c_path + "IMAGES\"
cWorkFile := "TEST.JPG"
cDestFile := "MYIMAGETEST"
nPenColor := 255
nPenSize := 5
nResize := 100
cExtension := "JPG"
hPen := CreatePen( 0, nPensize, nPenColor )
DEFINE DIALOG oDlg SIZE 800, 600
@ 0, 0 IMAGE oImg FILENAME NIL OF oDlg ;
SIZE 100, 100 PIXEL NOBORDER // any size, it will be adjusted
oImg:bPainted := { |hDC| ( IMGSIZE(cWorkfile, nResize), ;
DRAWIMG( hDC, oImg, cWorkFile, nResize ) ) }
oImg:cTooltip := "selected Image"
// @ 0, 0 IMAGE oImg FILE c_path1 + "TEST.JPG" ADJUST
@ 15, 0 BUTTON "Draw" ACTION DRAW( hDC )
@ 15, 20 BUTTON "Save";
ACTION SAVE_IMG(oDlg, oImg, cDestFile, cExtension)
ACTIVATE DIALOG oDlg CENTER ;
ON INIT ( IMGSIZE(cWorkfile, nResize), ;
hDC := oImg:GETDC(), ;
oImg:Move( 1, 1, nImgW * (nResize / 100), nImgH * (nResize / 100), .f. ) )
ReleaseDC( oImg:hWnd, hDC )
DeleteObject( hPen )
RETURN NIL
//-------------
STATIC FUNCTION IMGSIZE(cWorkfile, nResize)
LOCAL oTest
DEFINE IMAGE oTest FILENAME c_path1 + cWorkFile
nImgW := oTest:nWidth * (nResize / 100)
nImgH := oTest:nHeight * (nResize / 100)
oTest:End()
RETURN NIL
//-------------
FUNCTION DRAWIMG( hDC, oImg, cWorkFile, nResize )
LOCAL oBrush, hPen, oTest
IF FILE( c_path1 + cWorkFile )
oImg:Move( 0, 0, nImgW, nImgH, .f. )
// resize if needed witth % nResize
DEFINE IMAGE oBrush FILENAME c_path1 + cWorkFile
PalBmpDraw( hDC, 0, 0, oBrush:hBitmap, , nImgW, nImgH )
oBrush:End()
ELSE
IF !EMPTY(cWorkFile)
MsgAlert( "File : " + cWorkFile + CRLF + ;
"does not exist" + CRLF + ;
"to show Image !", "ATTENTION" )
ENDIF
ENDIF
RETURN( NIL )
// ----------------------------
STATIC FUNCTION SAVE_IMG(oDlg, oImg, cDestFile, cExtension)
LOCAL oImage, cExport := c_Path1 + ALLTRIM(cDestFile) + "." + cExtension
// Save the painted image as BMP
oImg:SaveToBmp( c_Path1 + ALLTRIM(cDestFile) + ".bmp" )
IF FILE ( c_Path1 + ALLTRIM(cDestFile) + ".bmp" )
// CONVERT if selected
IF cExtension <> "BMP"
@ 0, 0 IMAGE oImg SIZE 1, 1 OF oDlg
oImg:LoadBmp( c_Path1 + ALLTRIM(cDestFile) + ".bmp" )
oImg:SaveImage( cExport, 2, 25 )
oImg:End()
ENDIF
IF !FILE ( cExport )
MsgAlert( "Export-file : " + CRLF + ;
cExport + CRLF + ;
"not created !", "CREATION-ERROR" )
ELSE
MsgAlert( "Export-file : " + CRLF + ;
cExport + CRLF + ;
"created !", "FILE-CREATE" )
IF cExtension <> "BMP" // Delete the painted BMP
DELETE FILE ( c_Path1 + cDestFile + ".bmp" )
ENDIF
ENDIF
ELSE
MsgAlert( "BMP Export-file : " + CRLF + ;
c_Path1 + ALLTRIM(cDestFile) + ".bmp" + CRLF + ;
"is NOT created !", "ERROR" )
ENDIF
RETURN NIL
// --------------------------
STATIC FUNCTION DRAW( hDC )
LOCAL x, y
FOR y = 10 TO 50
FOR x = 10 TO 50
SETPIXEL( hDC, x, y, CLR_HRED )
NEXT
NEXT
RETURN NIL