Foxite.COM Community Weblog

Foxite.COM Community Weblog - free weblog service for the Visual FoxPro Community.
Welcome to Foxite.COM Community Weblog Sign in | Join | Help
in
Home Blogs Forum Photos Forum Archives

VFP IMAGING



HOW TO: Save Images in different formats with GdiPlus-X

That's a very easy task for GdiPlus-X:

IMPORTANT:

All samples below use the new GDIPlus-X library, that is still in ALPHA version, but is already stable and reliable to do the majority of GDI+ tasks. Download the latest stable release from Codeplex:

http://www.codeplex.com/Wiki/View.aspx?ProjectName=VFPX&title=GDIPlusX


DO LOCFILE("System.App")

WITH _SCREEN.System.Drawing

   LOCAL myBitmap AS xfcBitmap
   && Create a Bitmap object
   myBitmap = .Bitmap.New(GETPICT())

   && Save the bitmap in Different formats
   myBitmap.Save("c:\MyPNG.png", .Imaging.ImageFormat.Png)
   myBitmap.
Save("c:\MyBMP.bmp", .Imaging.ImageFormat.Bmp)
   myBitmap.
Save("c:\MyTIFF.tif", .Imaging.ImageFormat.Tiff)
   myBitmap.
Save("c:\MyJPEG.jpg", .Imaging.ImageFormat.Jpeg)
   myBitmap.
Save("c:\MyGIF.gif", .Imaging.ImageFormat.Gif)

ENDWITH
 
Of course, you can save as JPEG using the Quality Compression Encoder Parameter:
The sample below asks for an Image and saves it as JPEG with Wuality 25. Try the values from 0 to 100.


DO LOCFILE("System.App")

WITH _SCREEN.System.Drawing

LOCAL myBitmap AS xfcBitmap
LOCAL myEncoderParameter AS xfcEncoderParameter
LOCAL myEncoderParameters AS xfcEncoderParameters
&& Create a Bitmap object based on a BMP file.
myBitmap = .Bitmap.New(GETPICT("BMP"))

&& Create an EncoderParameters object.
&& An EncoderParameters object has an array of EncoderParameter objects
&& In this case, there is only one EncoderParameter object in the array.
myEncoderParameters = .Imaging.EncoderParameters.New(1)

&& Save the bitmap as a JPEG file with quality level 25.
&& Using an Encoder object based on the GUID
&& for the Quality parameter category.
myEncoderParameter = .Imaging.EncoderParameter.New(.Imaging.Encoder.Quality, 25)
myEncoderParameters.
Param.Add = myEncoderParameter
myBitmap.
Save("c:\MyJPEG_025.jpg", .Imaging.ImageFormat.Jpeg, myEncoderParameters)

ENDWITH

Published Thursday, February 22, 2007 1:58 PM by cesarchalom
Filed Under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Cesar Chalom said:

Este artículo fue traducido a espanol:

Como guardar imágenes en diferentes formatos con GdiPlus-X

June 27, 2007 7:26 PM
 

THomas Baehr said:

myEncoderParameters = .Imaging.EncoderParameters.New(1); <-- the ";" was really a hard thing for me to find out why it didnt work ( esp. also coding php so ; doesnt look too bad sometimes ;-)

and yes only happend coz i removed some remarks and closed some gaps so it was

myEncoderParameters = .Imaging.EncoderParameters.New(1);
myEncoderParameter = .Imaging.EncoderParameter.New(myEncoder, 100)


for me ... which really freeaked me out ...

Hi Thomas,

Thanks for reporting ! I've already updated the text above. Sorry for the inconvenience.

Regards

Cesar

July 9, 2007 5:36 PM
 

LuisMaria said:

Este articulo esta traducido en www.PortalFox.com

"Como guardar imágenes en diferentes formatos con GdiPlus-X"
http://www.portalfox.com/article.php?sid=2389

July 11, 2007 9:16 PM
 

Naten Baptista said:

During execution of the above code I seem to get the Program Error "ADD is a methode, event or Object" at the line

myEncoderParameters.PARAM.ADD = myEncoderParameter
August 18, 2008 10:43 PM

What do you think?

(required) 
(optional)
(required)