Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

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)

public static readonly Encoder Transformation
public static final Encoder Transformation
public static final var Transformation : Encoder
Not applicable.

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.

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;
    }
}

import System.* ;
import System.Drawing.* ;
import System.Drawing.Imaging.* ;

class Example_RotateJPEG
{
    public static void main(String[] args)
    {
        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.get_Param().set_Item( 0 , myEncoderParameter );
        myBitmap.Save("ShapesR90.jpg", myImageCodecInfo, myEncoderParameters);
    } //main

    private static ImageCodecInfo GetEncoderInfo(String mimeType) 
    {
        int j;
        ImageCodecInfo encoders[];
        encoders = ImageCodecInfo.GetImageEncoders();
        for(j = 0; j < encoders.length; j++) {
            if ( encoders[j].get_MimeType().Equals(mimeType)) {
                return encoders[j] ;
            }
        } 
        return null ;
    } //GetEncoderInfo
} //Example_RotateJPEG

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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft