For the latest release of GdiPlusX, we were obliged to aply an important modification in the Encoder Parameters class now instead of working with an array, has the "Param" property that is a "Collection" objects.
From now on, when you need to add an encoder parameter when saving an image, you need to use "Param.Add(EncoderParameter)". For me, it is difficult to explain, so let's skip the explanations to the new samples:
Many Thanks to Alfredo Reyna from Mexico, for bringing this to me. Gracias !
1 - CREATE A MULTIFRAME IMAGE
** Converted to GDIPlusX for VFP from .NET help:
** http://msdn2.microsoft.com/en-us/library/system.drawing.imaging.encoder.saveflag.aspx
** The following example creates three Bitmap objects:
** one from a BMP file, one from a JPEG file, and one from a PNG file.
** The code saves all three images in a single, multiple-frame TIFF file.
DO (LOCFILE("System.App"))
WITH _SCREEN.System.Drawing
LOCAL multif AS xfcBitmap
LOCAL page2 AS xfcBitmap
LOCAL page3 AS xfcBitmap
LOCAL myEncoder AS xfcEncoder
LOCAL myEncoderParameter AS xfcEncoderParameter
LOCAL myEncoderParameters AS xfcEncoderParameters
&& Create three Bitmap objects.
multif = .Bitmap.New(GETPICT())
page2 = .Bitmap.New(GETPICT())
page3 = .Bitmap.New(GETPICT())
&& Create an Encoder object based on the GUID
&& for the SaveFlag parameter category.
myEncoder = .Imaging.Encoder.SaveFlag
&& 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 first page (frame).
myEncoderParameter = .Imaging.EncoderParameter.New(myEncoder, .Imaging.EncoderValue.MultiFrame)
myEncoderParameters.Param.Add(myEncoderParameter)
multif.Save("c:\Multiframe.tif", .Imaging.ImageFormat.Tiff, myEncoderParameters)
*!* Save the second page (frame).
myEncoderParameter = .Imaging.EncoderParameter.New(myEncoder, .Imaging.EncoderValue.FrameDimensionPage)
myEncoderParameters.Param.Add(myEncoderParameter)
multif.SaveAdd(page2, myEncoderParameters)
*!* Save the third page (frame).
myEncoderParameter = .Imaging.EncoderParameter.New(myEncoder, .Imaging.EncoderValue.FrameDimensionPage)
myEncoderParameters.Param.Add(myEncoderParameter)
multif.SaveAdd(page3, myEncoderParameters)
*!* Close the multiple-frame file.
myEncoderParameter = .Imaging.EncoderParameter.New(myEncoder, .Imaging.EncoderValue.Flush)
myEncoderParameters.Param.Add(myEncoderParameter)
multif.SaveAdd(myEncoderParameters)
ENDWITH
RETURN
2 - EXTRACT FRAMES FROM MULTIFRAME TIFF
** HOWTO: Extract frames from a Multiframe TIFF
DO LOCFILE ("System.App")
WITH _SCREEN.System.Drawing
* Load the multiframe TIFF to GDI+
LOCAL loMultif AS xfcBitmap
loMultif = .Bitmap.New(GETPICT("TIF"))
LOCAL lnFrames, n, lcFrameFileName
lnFrames = loMultif.GetFrameCount()
IF lnFrames > 1
FOR n = 0 TO lnFrames - 1
loMultif.SelectActiveFrame(.Imaging.FrameDimension.Page, n)
lcFrameFileName = "c:\Frame" + TRANSFORM(n + 1) + ".bmp"
loMultif.Save(lcFrameFileName, .Imaging.ImageFormat.Bmp)
ENDFOR
ELSE
MESSAGEBOX("The selected file is not a Multiframe TIFF")
ENDIF
ENDWITH
RETURN
3 - SETTING TIFFS COMPRESSION
** HOWTO: Set Tiff Compression
** http://msdn2.microsoft.com/en-us/library/system.drawing.imaging.encoder.compression.aspx
DO LOCFILE("System.App")
WITH _SCREEN.System.Drawing
LOCAL loMyBitmap AS xfcBitmap
LOCAL myEncoder AS xfcEncoder
LOCAL myEncoderParameters AS xfcEncoderParameters
* Create a Bitmap object based on a BMP file.
loMyBitmap = .Bitmap.New(GETPICT())
* Create an Encoder object based on the GUID
* for the Compression parameter category.
myEncoder = .Imaging.Encoder.Compression
* 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 TIFF file with LZW compression.
myEncoderParameters.Param.Add(.Imaging.EncoderParameter.New(myEncoder, .Imaging.EncoderValue.CompressionLZW))
loMyBitmap.Save("c:\ImageLZW.tif", .Imaging.ImageFormat.Tiff, myEncoderParameters)
* Save the bitmap as a TIFF file with NONE compression.
myEncoderParameters.Param.Add(.Imaging.EncoderParameter.New(myEncoder, .Imaging.EncoderValue.CompressionNone))
loMyBitmap.Save("c:\ImageNONE.tif", .Imaging.ImageFormat.Tiff, myEncoderParameters)
* Convert the original Bitmap to Monochrome
LOCAL loMonoChrBmp as xfcBitmap
loMonoChrBmp = loMyBitmap.GetMonochrome()
* Dispose the original Bitmap because we don't need it any more
loMyBitmap = NULL
* Go on with the compressions using the monochromatic version of the selected image
* Save the bitmap as a TIFF file with RLE compression.
myEncoderParameters.Param.Add(.Imaging.EncoderParameter.New(myEncoder, .Imaging.EncoderValue.CompressionRle))
loMonoChrBmp.Save("c:\ImageRLE.tif", .Imaging.ImageFormat.Tiff, myEncoderParameters)
* Save the bitmap as a TIFF file with CCITT3 compression.
myEncoderParameters.Param.Add(.Imaging.EncoderParameter.New(myEncoder, .Imaging.EncoderValue.CompressionCCITT3))
loMonoChrBmp.Save("c:\ImageCCITT3.tif", .Imaging.ImageFormat.Tiff, myEncoderParameters)
* Save the bitmap as a TIFF file with CCITT4 compression.
myEncoderParameters.Param.Add(.Imaging.EncoderParameter.New(myEncoder, .Imaging.EncoderValue.CompressionCCITT4))
loMonoChrBmp.
Save("c:\ImageCCITT4.tif", .Imaging.ImageFormat.Tiff, myEncoderParameters)
ENDWITH
RETURN
* CompressionCCITT3
* Specifies the CCITT3 compression scheme. Can be passed to the TIFF encoder as a parameter that belongs to the compression category.
* CompressionCCITT4
* Specifies the CCITT4 compression scheme. Can be passed to the TIFF encoder as a parameter that belongs to the compression category.
* CompressionLZW
* Specifies the LZW compression scheme. Can be passed to the TIFF encoder as a parameter that belongs to the Compression category.
* CompressionNone
* Specifies no compression. Can be passed to the TIFF encoder as a parameter that belongs to the compression category.
* CompressionRle
* Specifies the RLE compression scheme.
* Can be passed to the TIFF encoder as a parameter that belongs to the compression category.