Leadtools.Codecs Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.12.17
Transform Method
See Also  Example
Leadtools.Codecs Namespace > RasterCodecs Class : Transform Method




srcFileName
A String containing the name of the source file.
destFileName
A String containing the name of the destination file.
flags

Indicates the transform to be performed. Possible values are:

ValueMeaning
CodecsTransformFlags.FlipFlip the image vertically
CodecsTransformFlags.ReverseReverse the image (flip horizontally)
CodecsTransformFlags.Rotate90Rotate the image clockwise by 90 degrees
CodecsTransformFlags.Rotate180Rotate the image clockwise by 180 degrees
CodecsTransformFlags.Rotate270Rotate the image clockwise by 270 degrees
CodecsTransformFlags.NoneDo nothing

pageNumber
1-based index of the page within the source file to process.
callback

Optional callback method for processing custom markers. (This is useful for rotating JPEG files only). When transforming JPEG files, the method will enumerate all the markers contained in the file and it will pass them to this callback. The user has the ability to control the transformation for all the markers. For additional information on JPEG markers, please consult the JPEG specification.

  • If you do not provide a callback method, use a null reference (Nothing in Visual Basic) as the value of this parameter and no JPEG markers will be transformed
  • If you do provide a callback method, use a delegate to a method that has the same signature as CodecsTransformMarkerCallback as the value of this parameter

Performs a lossless transformation for certain formats.

Syntax

Visual Basic (Declaration) 
Public Sub Transform( _
   ByVal srcFileName As String, _
   ByVal destFileName As String, _
   ByVal flags As CodecsTransformFlags, _
   ByVal pageNumber As Integer, _
   ByVal callback As CodecsTransformMarkerCallback _
) 
Visual Basic (Usage)Copy Code
Dim instance As RasterCodecs
Dim srcFileName As String
Dim destFileName As String
Dim flags As CodecsTransformFlags
Dim pageNumber As Integer
Dim callback As CodecsTransformMarkerCallback
 
instance.Transform(srcFileName, destFileName, flags, pageNumber, callback)
Managed Extensions for C++ 
public: void Transform( 
   string* srcFileName,
   string* destFileName,
   CodecsTransformFlags flags,
   int pageNumber,
   CodecsTransformMarkerCallback* callback
) 
C++/CLI 
public:
void Transform( 
   String^ srcFileName,
   String^ destFileName,
   CodecsTransformFlags flags,
   int pageNumber,
   CodecsTransformMarkerCallback^ callback
) 

Parameters

srcFileName
A String containing the name of the source file.
destFileName
A String containing the name of the destination file.
flags

Indicates the transform to be performed. Possible values are:

ValueMeaning
CodecsTransformFlags.FlipFlip the image vertically
CodecsTransformFlags.ReverseReverse the image (flip horizontally)
CodecsTransformFlags.Rotate90Rotate the image clockwise by 90 degrees
CodecsTransformFlags.Rotate180Rotate the image clockwise by 180 degrees
CodecsTransformFlags.Rotate270Rotate the image clockwise by 270 degrees
CodecsTransformFlags.NoneDo nothing

pageNumber
1-based index of the page within the source file to process.
callback

Optional callback method for processing custom markers. (This is useful for rotating JPEG files only). When transforming JPEG files, the method will enumerate all the markers contained in the file and it will pass them to this callback. The user has the ability to control the transformation for all the markers. For additional information on JPEG markers, please consult the JPEG specification.

  • If you do not provide a callback method, use a null reference (Nothing in Visual Basic) as the value of this parameter and no JPEG markers will be transformed
  • If you do provide a callback method, use a delegate to a method that has the same signature as CodecsTransformMarkerCallback as the value of this parameter

Example

Visual BasicCopy Code
RasterCodecs.Transform
      Public Sub TransformExample()
         RasterCodecs.Startup()
         Dim codecs As RasterCodecs = New RasterCodecs()

         Dim srcFileName As String = "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1.cmp"

         Dim destFileName As String = "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1_Transform.cmp"

         codecs.Transform(srcFileName, destFileName, CodecsTransformFlags.Rotate90, 1, AddressOf MyCodecsTransformMarkerCallback)

         ' Clean up
         codecs.Dispose()
         RasterCodecs.Shutdown()
      End Sub

      Private Function MyCodecsTransformMarkerCallback(ByVal id As Integer, ByVal data As IntPtr, ByVal dataLength As Integer, ByVal transform As CodecsTransformFlags) As CodecsTransformMarkerAction
         Console.WriteLine("Transforming: id: {0}, dataLength: {1}, transform: {2}", id, dataLength, transform)
         Return CodecsTransformMarkerAction.Default
      End Function
C#Copy Code
RasterCodecs.Transform 
      public void TransformExample() 
      { 
         RasterCodecs.Startup(); 
         RasterCodecs codecs = new RasterCodecs(); 
 
         string srcFileName = @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1.cmp"; 
 
         string destFileName = @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1_Transform.cmp"; 
 
         codecs.Transform( 
            srcFileName, 
            destFileName, 
            CodecsTransformFlags.Rotate90, 
            1, 
            MyCodecsTransformMarkerCallback); 
 
         // Clean up 
         codecs.Dispose(); 
         RasterCodecs.Shutdown(); 
      } 
 
      CodecsTransformMarkerAction MyCodecsTransformMarkerCallback(int id, IntPtr data, int dataLength, CodecsTransformFlags transform) 
      { 
         Console.WriteLine("Transforming: id: {0}, dataLength: {1}, transform: {2}", id, dataLength, transform); 
         return CodecsTransformMarkerAction.Default; 
      }

Remarks

Currently, only JPEG, CMP and JPEG TIFF formats are supported.

Only one of the rotate flags can be specified.

The files transformed by this method will be read transformed by other applications capable of reading these file formats.

JPEG and Exif JPEG stamps are transformed according to the flags specified in flags. Please note that some JPEG stamps will not be transformed by this method. Specifically, stamps stored in markers other than APP0 and APP1 will not be transformed. Use the callback parameter to handle these cases. For example, if a stamp is in the APP14 marker, check for this in the callback and write your own stamp using SaveStamp.

For JPEG files, the size of the image might be changed. This can happen when the image width or height is not a multiple of 8.

The transformation is lossless. It is better than loading the image, transforming it using RotateCommand or FlipCommand and resaving it. Repeated load and save process will cause image degradation, but calling this method will not cause any image degradation.

The rotation transformations are performed before the flip/reverse operations.

Use the WriteTransformMarker method to control how the transform markers are used.

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also