Export (0) Print
Expand All

JpegBitmapEncoder Class

Defines an encoder that is used to encode Joint Photographics Experts Group (JPEG) format images.

Namespace:  System.Windows.Media.Imaging
Assembly:  PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

public sealed class JpegBitmapEncoder : BitmapEncoder

The JpegBitmapEncoder type exposes the following members.

  NameDescription
Public methodJpegBitmapEncoderInitializes a new instance of the JpegBitmapEncoder class.
Top

  NameDescription
Public propertyCodecInfoGets information that describes this codec. (Inherited from BitmapEncoder.)
Public propertyColorContextsGets or sets a value that represents the color profile that is associated with this encoder. (Inherited from BitmapEncoder.)
Public propertyDispatcherGets the Dispatcher this DispatcherObject is associated with. (Inherited from DispatcherObject.)
Public propertyFlipHorizontalGets or sets a value that indicates whether a Joint Photographics Experts Group (JPEG) image should be flipped horizontally during encoding.
Public propertyFlipVerticalGets or sets a value that indicates whether a Joint Photographics Experts Group (JPEG) image should be flipped vertically during encoding.
Public propertyFramesGets or sets the individual frames within an image. (Inherited from BitmapEncoder.)
Public propertyMetadataGets or sets the metadata that will be associated with this bitmap during encoding. (Inherited from BitmapEncoder.)
Public propertyPaletteGets or sets a value that represents the BitmapPalette of an encoded bitmap. (Inherited from BitmapEncoder.)
Public propertyPreviewGets or sets a BitmapSource that represents the global preview of a bitmap, if there is one. (Inherited from BitmapEncoder.)
Public propertyQualityLevelGets or sets a value that indicates the quality level of the resulting Joint Photographics Experts Group (JPEG) image.
Public propertyRotationGets or sets a value that represents the degree to which a Joint Photographics Experts Group (JPEG) image is rotated.
Public propertyThumbnailGets or sets a BitmapSource that represents the global embedded thumbnail. (Inherited from BitmapEncoder.)
Top

  NameDescription
Public methodCheckAccessDetermines whether the calling thread has access to this DispatcherObject. (Inherited from DispatcherObject.)
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodSaveEncodes a bitmap image to a specified Stream. (Inherited from BitmapEncoder.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodVerifyAccessEnforces that the calling thread has access to this DispatcherObject. (Inherited from DispatcherObject.)
Top

Joint Photographics Experts Group (JPEG) format bitmaps support frame level thumbnails and frame level metadata. They do not support preview, global thumbnails, global metadata, or multiple frames.

Encoding does not work in partial trust. See WPF Partial Trust Security for information on partial trust.

The following examples show how to decode and encode a JPEG image using the specific JpegBitmapDecoder and JpegBitmapEncoder objects.

This example demonstrates how to decode a JPEG image using a JpegBitmapDecoder from a FileStream.


// Open a Stream and decode a JPEG image
Stream imageStreamSource = new FileStream("tulipfarm.jpg", FileMode.Open, FileAccess.Read, FileShare.Read);
JpegBitmapDecoder decoder = new JpegBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapSource bitmapSource = decoder.Frames[0];

// Draw the Image
Image myImage = new Image();
myImage.Source = bitmapSource;
myImage.Stretch = Stretch.None;
myImage.Margin = new Thickness(20);

This example demonstrates how to encode a BitmapSource into a JPEG image using a JpegBitmapEncoder.

            int width = 128;
            int height = width;
            int stride = width / 8;
            byte[] pixels = new byte[height * stride];

            // Define the image palette
            BitmapPalette myPalette = BitmapPalettes.Halftone256;

            // Creates a new empty image with the pre-defined palette
            BitmapSource image = BitmapSource.Create(
                width,
                height,
                96,
                96,
                PixelFormats.Indexed1,
                myPalette,
                pixels,
                stride);

            FileStream stream = new FileStream("new.jpg", FileMode.Create);
            JpegBitmapEncoder encoder = new JpegBitmapEncoder();
            TextBlock myTextBlock = new TextBlock();
            myTextBlock.Text = "Codec Author is: " + encoder.CodecInfo.Author.ToString();
            encoder.FlipHorizontal = true;
            encoder.FlipVertical = false;
            encoder.QualityLevel = 30;
            encoder.Rotation = Rotation.Rotate90;
            encoder.Frames.Add(BitmapFrame.Create(image));
            encoder.Save(stream);

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft