SET PROCEDURE TO gdiplus ADDITIVE
* an instance of gdiplusinit should be created before
* and released after using any of gdi+ objects
LOCAL gdip
gdip = CREATEOBJECT("gdiplusinit")
* source and target files
LOCAL cSrcFile, cDstFile
cSrcFile = "c:\windows\forest.bmp"
cDstFile = SYS(2023) + "\test.jpg"
*create Image object from the source file
LOCAL src As gdiimage
src = CREATEOBJECT("gdiimage", cSrcFile)
IF src.himage = 0
? "Could not load source image file."
RETURN
ENDIF
* set crop coordinates and dimensions
LOCAL cropLeft, cropTop, cropWidth, cropHeight
cropLeft = 10
cropTop = 80
cropWidth = src.imgwidth - m.cropLeft
cropHeight = 60
* create destination Bitmap object using crop dimensions
LOCAL dst As gdibitmap
dst = CREATEOBJECT("gdibitmap", m.cropWidth, m.cropHeight)
* draw source image on the target bitmap;
* note how coordinates and dimensions are set
dst.graphics.DrawImage(src, -m.cropLeft, -m.cropTop,;
src.imgwidth, src.imgheight)
IF NOT dst.SaveToFile(cDstFile)
? "Could not save file", cDstFile
ELSE
* open the file using default application
DECLARE INTEGER ShellExecute IN shell32;
INTEGER hwnd, STRING lpOperation,;
STRING lpFile, STRING lpParameters,;
STRING lpDirectory, INTEGER nShowCmd
= ShellExecute(0, "open", cDstFile, "", "", 3)
ENDIF
|