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



Use encoder parameters to save your images with GDI+

The method SaveToFile from GpImage class in _gdiplus.vcx from VFP9 “Saves the image object to a disk file, using specified encoder or image format and optional parameters.”

Here are the most important:

QUALITY (Supported by JPEG)

Specifies the compression level when you save a JPEG image. A quality level of 0 corresponds to the greatest compression, and a quality level of 100 corresponds to the least compression.


Example 1: Saves image with quality of 70%

LOCAL lcSource
lcSource = GETPICT()
LOCAL loImage AS GpImage OF HOME() + ffc/_gdiplus.vcx
loImage = NEWOBJECT("GpImage", HOME() + "ffc/_gdiplus.vcx")
loImage.CreateFromFile(lcSource)
loImage.SaveToFile("c:\MyImage.jpg","image/jpeg", "quality=70")


TRANSFORMATION (Supported by JPEG)

GDI+ provides the following transformations that can be performed on JPEG images without loss of information:

         Rotate 90 degrees
         Rotate 180 degrees
         Rotate 270 degrees
         Flip horizontally
         Flip vertically
 

Each of those listed above corresponds to a Gdiplus Constant, that needs to be passed together with the “transformation” encoder.

The transformation will proceed without loss of information if the file used to construct the Image object is a JPEG file and the width and height of the image are both multiples of 16. If the width and height of the image are not both multiples of 16, GDI+ will do its best to preserve the image quality when you apply one of the rotation or flipping transformations.


Example 2: Saves image with quality of 50% AND Rotate 180 degrees

#DEFINE EncoderValueTransformRotate90       13
#DEFINE EncoderValueTransformRotate180      14
#DEFINE EncoderValueTransformRotate270      15
#DEFINE EncoderValueTransformFlipHorizontal 16
#DEFINE EncoderValueTransformFlipVertical   17

LOCAL lcSource
lcSource = GETPICT()
LOCAL loImage AS GpImage OF HOME() + ffc/_gdiplus.vcx
loImage = NEWOBJECT("GpImage", HOME() + "ffc/_gdiplus.vcx")
loImage.CreateFromFile(lcSource)
loImage.SaveToFile("c:\MyImage.jpg","image/jpeg", ;
              "quality=50, transformation=14")


This makes rotating and flipping a very simple and quick operation!


For TIFF Images, these are the commonest parameters:

 

SAVEFLAG (Supported by TIFF)

         See my article at UTMAG from May 2006: “Multiframe Images with GDI+”
         http://www.utmag.com/wconnect/wc.dll?9,7,10,,2115
         Used for the creation and manipulation of multiframed images.

 

COMPRESSION (Supported by TIFF)

         #DEFINE EncoderValueCompressionLZW    2
         #DEFINE EncoderValueCompressionCCITT3 3
         #DEFINE EncoderValueCompressionCCITT4 4
         #DEFINE EncoderValueCompressionRle    5
         #DEFINE EncoderValueCompressionNone   6

 

COLORDEPTH (Supported by TIFF)
         Color Depth in Bytes per pixel.

 

These are defined by GDI+ but not supported by any of the standard encoders: 'COMPRESSION', 'SCANMETHOD', 'VERSION' and 'RENDERMETHOD'.

Source: MSDN

See also this blog post: ROTATE / FLIP IMAGES WITH VFP9 AND GDI+

Published Saturday, June 10, 2006 11:23 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

 

Luis Navas said:

Hi Cesar, one question, what if you already have a GDI object like in reports listeners, and you want to save it to disk. For example:

Instead of this line
loImage.CreateFromFile(lcSource)
You already has loImage but with a Handle the way that reportlistener does, and I want to do a:
loImage.SaveToFile("c:\MyImage.jpg","image/jpeg", "quality=70")

How can you do that?

Thaks


June 15, 2006 7:44 PM
 

Cesar Chalom said:

Hi Luis,
Sorry, but I'm not too familiar with this feature !
Maybe you should look for Cathy Pountney's great articles on MSDN.
July 19, 2006 7:56 PM
 

Ana María Bisbé said:

Versión en Español de este artículo en / Spanish version at http://www.portalfox.com/article.php?sid=2216
July 24, 2007 6:47 PM

What do you think?

(required) 
(optional)
(required)