Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to re-size image file with vfp
Message
De
30/04/2010 09:06:56
Hee Lim Wang
Fantasy Software Enterprise
Malaisie
 
 
À
30/04/2010 05:32:08
Information générale
Forum:
Visual FoxPro
Catégorie:
Photos et traitement d'images
Divers
Thread ID:
01462492
Message ID:
01462512
Vues:
54
Thanks a lot Tore !


Download GDIPlusX from http://vfpx.codeplex.com/wikipage?title=GDIPlusX&referringTitle=Home. This is my Imgresize function which will make sure that the image ratio is maintained. I use it to resize images for my webshop, so I have added default values for width and height, these are used unless specified. Set the third parameter to .T. if you want high quality pictures. The return value is the number of bytes in the new picture file.

Lparameters pcFromFile, pcToFile, plHQ, pnWidth, pnHeight
Do Case
Case Type('pcFromFile')#'C'
Case !Empty(Justext(pcFromFile))
Case Adir(temp,pcFromFile)=0
Otherwise
Return -1
Endcase
Local lcType, lnWidth, lnHeight, loZ, lnRatio, lnMaxWidth, lnMaxHeight, loSrcImage, loResized,;
loGfx, loType, lnReturn, lcTempfile, lnReturn
lnReturn=0
If Type('pnHeight')='N'
lnMaxHeight=pnHeight
Else
lnMaxHeight=600
Endif
If Type('pnWidth')='N'
lnMaxWidth=pnWidth
Else
lnMaxWidth=800
Endif
If Type('pcToFile')#'C'
pcToFile = pcFromFile
Endif
If Empty(Justext(pcToFile))
pcTofile=Forceext(pcTofile,Justext(pcFromfile))
Endif
If !type('_screen.system')='O'
Do prog\gdiplusx\app\system.app
Endif
lcType=Upper(Justext(pcToFile))
If Lower(pcFromFile)==Lower(pcToFile)
lcTempfile=Sys(2023)+'\'+Sys(3)+'.'+lcType
Copy File (pcFromFile) To (lcTempfile)
Erase (pcFromFile)
pcFromFile = lcTempfile
Endif
If plHQ
With _screen.system.Drawing
loSrcImage = .Bitmap.New(pcFromFile)
lnWidth=loSrcImage.width
lnHeight=loSrcImage.height
lnRatio = Min(lnMaxHeight/lnHeight, lnMaxWidth/lnWidth)
lnWidth=lnWidth*lnRatio
lnHeight = lnHeight*lnRatio
loResized = .Bitmap.New(lnWidth, lnHeight,.Imaging.PixelFormat.Format32bppARGB)
loResized.SetResolution(loSrcImage.HorizontalResolution, loSrcImage.VerticalResolution)
loGfx = .Graphics.FromImage(loResized)
loGfx.SmoothingMode = .Drawing2D.SmoothingMode.HighQuality
loGfx.InterpolationMode = .Drawing2D.InterpolationMode.HighQualityBicubic
loGfx.DrawImage(loSrcImage, 0, 0, lnWIdth, lnHeight)
Do Case
Case lcType='TIF'
loType='.Imaging.ImageFormat.Tiff'
Case lcType='JPG'
loType='.Imaging.ImageFormat.Jpeg'
Case lcType='PNG'
loType='.Imaging.ImageFormat.Png'
Case lcType='GIF'
loType='.Imaging.ImageFormat.Gif'
Case lcType='BMP'
loType='.Imaging.ImageFormat.Bmp'
Endcase
loResized.Save(pcToFile, &loType)
Endwith
Else
With _screen.system.Drawing
* Load the original Image
loSrcImage = .Bitmap.New(pcFromFile)
lnWidth=loSrcImage.width
lnHeight=loSrcImage.height
lnRatio = Min(lnMaxHeight/lnHeight, lnMaxWidth/lnWidth)
lnWidth=lnWidth*lnRatio
lnHeight = lnHeight*lnRatio
loResized = loSrcImage.GetThumbnailImage(lnWidth, lnHeight)
Do Case
Case lcType='TIF'
loType='.Imaging.ImageFormat.Tiff'
Case lcType='JPG'
loType='.Imaging.ImageFormat.Jpeg'
Case lcType='PNG'
loType='.Imaging.ImageFormat.Png'
Case lcType='GIF'
loType='.Imaging.ImageFormat.Gif'
Case lcType='BMP'
loType='.Imaging.ImageFormat.Bmp'
Endcase
loResized.Save(pcToFile, &loType)
Endwith
Endif
loSrcImage =.null.
Release loSrcImage
loResized=.null.
Release loResized
If !Empty(lcTempfile)
Erase (lcTempfile)
Endif
If lnReturn=0 And Adir(temp,pcToFile)>0
lnReturn=temp(1,2)
Endif
Return lnReturn
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform