Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
Encoder Class
Encoder Fields
 Transformation Field
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
Encoder..::.Transformation Field

Represents an Encoder object that is initialized with the globally unique identifier for the transformation parameter category.

Namespace:  System.Drawing.Imaging
Assembly:  System.Drawing (in System.Drawing.dll)
Visual Basic (Declaration)
Public Shared ReadOnly Transformation As Encoder
Visual Basic (Usage)
Dim value As Encoder

value = Encoder.Transformation
C#
public static readonly Encoder Transformation
Visual C++
public:
static initonly Encoder^ Transformation
JScript
public static final var Transformation : Encoder

The following example creates a Bitmap object from a JPEG file. The code rotates the image 90 degrees and saves it in a separate JPEG file.

Visual Basic
Imports System
Imports System.Drawing
Imports System.Drawing.Imaging


Class Example_RotateJPEG

    Public Shared Sub Main() 
        Dim myBitmap As Bitmap
        Dim myImageCodecInfo As ImageCodecInfo
        Dim myEncoder As Encoder
        Dim myEncoderParameter As EncoderParameter
        Dim myEncoderParameters As EncoderParameters

        ' Create a Bitmap object based on a JPEG file.
        myBitmap = New Bitmap("Shapes.jpg")

        ' Get an ImageCodecInfo object that represents the JPEG codec.
        myImageCodecInfo = GetEncoderInfo("image/jpeg")

        ' Create an Encoder object based on the GUID
        ' for the Transformation parameter category.
        myEncoder = Encoder.Transformation

        ' 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 = New EncoderParameters(1)

        ' Rotate the image 90 degrees, and save it as a separate JPEG file.
        myEncoderParameter = New EncoderParameter(myEncoder, Fix(EncoderValue.TransformRotate90))
        myEncoderParameters.Param(0) = myEncoderParameter
        myBitmap.Save("ShapesR90.jpg", myImageCodecInfo, myEncoderParameters)

    End Sub 'Main

    Private Shared Function GetEncoderInfo(ByVal mimeType As String) As ImageCodecInfo 
        Dim j As Integer
        Dim encoders() As ImageCodecInfo
        encoders = ImageCodecInfo.GetImageEncoders()

        j = 0
        While j < encoders.Length
            If encoders(j).MimeType = mimeType Then
                Return encoders(j)
            End If
            j += 1
        End While
        Return Nothing

    End Function 'GetEncoderInfo
End Class 'Example_RotateJPEG
C#
using System;
using System.Drawing;
using System.Drawing.Imaging;
class Example_RotateJPEG
{
    public static void Main()
    {
        Bitmap myBitmap;
        ImageCodecInfo myImageCodecInfo;
        Encoder myEncoder;
        EncoderParameter myEncoderParameter;
        EncoderParameters myEncoderParameters;

        // Create a Bitmap object based on a JPEG file.
        myBitmap = new Bitmap("Shapes.jpg");

        // Get an ImageCodecInfo object that represents the JPEG codec.
        myImageCodecInfo = GetEncoderInfo("image/jpeg");

        // Create an Encoder object based on the GUID
        // for the Transformation parameter category.
        myEncoder = Encoder.Transformation;

        // 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 = new EncoderParameters(1);

        // Rotate the image 90 degrees, and save it as a separate JPEG file.
        myEncoderParameter = new EncoderParameter(
            myEncoder,
            (long)EncoderValue.TransformRotate90);
        myEncoderParameters.Param[0] = myEncoderParameter;
        myBitmap.Save("ShapesR90.jpg", myImageCodecInfo, myEncoderParameters);
    }
    private static ImageCodecInfo GetEncoderInfo(String mimeType)
    {
        int j;
        ImageCodecInfo[] encoders;
        encoders = ImageCodecInfo.GetImageEncoders();
        for(j = 0; j < encoders.Length; ++j)
        {
            if(encoders[j].MimeType == mimeType)
                return encoders[j];
        }
        return null;
    }
}
Visual C++
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::Drawing::Imaging;
static ImageCodecInfo^ GetEncoderInfo( String^ mimeType );
int main()
{
   Bitmap^ myBitmap;
   ImageCodecInfo^ myImageCodecInfo;
   Encoder^ myEncoder;
   EncoderParameter^ myEncoderParameter;
   EncoderParameters^ myEncoderParameters;

   // Create a Bitmap object based on a JPEG file.
   myBitmap = gcnew Bitmap( "Shapes.jpg" );

   // Get an ImageCodecInfo object that represents the JPEG codec.
   myImageCodecInfo = GetEncoderInfo( "image/jpeg" );

   // Create an Encoder object based on the GUID
   // for the Transformation parameter category.
   myEncoder = Encoder::Transformation;

   // 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 = gcnew EncoderParameters( 1 );

   // Rotate the image 90 degrees, and save it as a separate JPEG file.
   myEncoderParameter = gcnew EncoderParameter( myEncoder,(__int64)EncoderValue::TransformRotate90 );
   myEncoderParameters->Param[ 0 ] = myEncoderParameter;
   myBitmap->Save( "ShapesR90.jpg", myImageCodecInfo, myEncoderParameters );
}

static ImageCodecInfo^ GetEncoderInfo( String^ mimeType )
{
   int j;
   array<ImageCodecInfo^>^encoders;
   encoders = ImageCodecInfo::GetImageEncoders();
   for ( j = 0; j < encoders->Length; ++j )
   {
      if ( encoders[ j ]->MimeType == mimeType )
            return encoders[ j ];

   }
   return nullptr;
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker