JpegBitmapDecoder Class
Defines a decoder for Joint Photographics Experts Group (JPEG) encoded images.
Assembly: PresentationCore (in PresentationCore.dll)
The following table list the PixelFormats that are supported by the JpegBitmapDecoder class.
The following examples show how to decode and encode a JPEG image using the specific JpegBitmapDecoder and JpegBitmapEncoder objects. For the complete sample, see JPEG Encoder and Decoder Sample.
This example demonstrates how to decode a JPEG image using a JpegBitmapDecoder from a FileStream.
' Open a Stream and decode a JPEG image Dim imageStreamSource As New FileStream("tulipfarm.jpg", FileMode.Open, FileAccess.Read, FileShare.Read) Dim decoder As New JpegBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default) Dim bitmapSource As BitmapSource = decoder.Frames(0) ' Draw the Image Dim myImage As 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.
Dim width As Integer = 128 Dim height As Integer = width Dim stride As Integer = CType(width / 8, Integer) Dim pixels(height * stride) As Byte ' Define the image palette Dim myPalette As BitmapPalette = BitmapPalettes.Halftone256 ' Creates a new empty image with the pre-defined palette Dim image As BitmapSource = System.Windows.Media.Imaging.BitmapSource.Create(width, height, 96, 96, PixelFormats.Indexed1, myPalette, pixels, stride) Dim stream As New FileStream("new.jpg", FileMode.Create) Dim encoder As New JpegBitmapEncoder() Dim myTextBlock As 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)
System.Windows.Threading.DispatcherObject
System.Windows.Media.Imaging.BitmapDecoder
System.Windows.Media.Imaging.JpegBitmapDecoder
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
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.