Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
VFP5 to 6 Upgrade for jpg
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00317537
Message ID:
00319257
Vues:
16
> And I will be happy if I can
>try it out in VFP 5 without having to get VFP 6 right away.

I still recommend upgrading to VFP6. To display a JPeg with VFP6, you simply put a picture object on your form with the form builder, and then use code like:

Thisform.oMyPicture.Picture="C:\MyImages\MyJpegImage.JPG"

... which will display the image in the picture object. Also, be sure to read about picture object STRETCH property.

>I am not experienced with calling dlls with api in vfp, and I am not
>certain that I know enough about objects to properly use the "encapsulated"
>code that you offered....

Keep in mind that the DLL will not display the image. But the DLL is simple to use for reading, manipulating, and rewriting the image to disk. The DLL itself allocates memory from the Windows global heap for any image that the DLL reads from disk or generates. In order to keep track of this section of memory, the DLL returns to you the handle to any newly allocated section of memory (e.g., when telling the DLL to read an image from disk). The image stays in this section of allocated memory between calls to the DLL... say, for example, when you make a call to first read the image, then make a call to rotate it. The only real caveat is that you need to remember to use some simple Windows API functions for Locking/Unlocking/Freeing those memory sections so that you don't create memory conflicts or leaks. The technique is well-described in the docs.

Here's some sample code for cropping an image from uLeft,uTop to uRight,uBottom and writing the image back to disk with quality factor of iQualFactor



Procedure Resize
Param cInputFile,cOutPutFile,uLeft, uTop, uRight, uBottom,iQualFactor

Declare Integer ImgDLLReadRGBFromJPG in ImgDLL String @Filename, Integer @Width, Integer @Height
declare integer ImgDLLCropRGB in ImgDLL Integer pRGB, Integer InW, Integer inH, Integer uLeft, Integer uTop, Integer uRight, Integer uBottom
declare integer ImgDLLSaveRGBToJPG in ImgDLL String @FileName, Integer pRGBBuf, Integer W, Integer H, Integer Qual, Integer ColorFlag, Integer ProgressiveFlag
Declare GlobalUnlock in Win32API Integer hpRGB
Declare GlobalFree in Win32API Integer hpRGB
declare integer GlobalLock in Win32API Integer hpRGB

iWid=0
iHeight=0
hpRGB=ImgDLLReadRGBFromJPG(@cInputFile,@iWid,@iHeight) && Read image from disk
If hpRGB = 0
Message("Reading input file")
Return
Endif
pRGB=GlobalLock(hpRGB)
If pRGB = 0
* This should never happen
GlobalFree(hpRGB)
ErrMsg("Getting global lock on input buffer")
Return
Endif
hpRGBNew=ImgDLLCropRGB(pRGB, iWid, iHeight, uLeft, uTop, uRight, uBottom)
If hpRGBNew = 0
* Error happened
GlobalUnlock(hpRGB) && Free the original input file's buffer
GlobalFree(hpRGB)
ErrMsg("Cropping file")
Return
Endif
pRGBNew=GlobalLock(hpRGBNew) && Lock the cropped image buffer
GlobalUnlock(hpRGB) && Free the original input file's buffer
GlobalFree(hpRGB)
NewIWid=uRight-uLeft
NewIHeight=uBottom-uTop
iStat=ImgDLLSaveRGBToJPG(@cOutPutFile, pRGBNew, NewIWid, NewIHeight, iQualFactor, 1,0)
If iStat <> 1
ErrMsg("Saving to resized JPG")
Endif
GlobalUnlock(hpRGBNew)
GlobalFree(hpRGBNew) && Free the cropped image buffer
Return


Procedure ErrMsg
LParam txtInfo
Priv iStat
iStat=ImgDLLGetLastError()
MSG("ImgDLL Error " + txtInfo + ", error: " + allt(str(iStat)) )
Return

Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform