Skip to main content
.NET Framework Class Library
PixelFormats Class

Represents the collection of supported pixel formats.

Inheritance Hierarchy
SystemObject
  System.Windows.MediaPixelFormats

Namespace:   System.Windows.Media
Assembly:  PresentationCore (in PresentationCore.dll)
Syntax
Public NotInheritable Class PixelFormats
public static class PixelFormats
public ref class PixelFormats abstract sealed
[<[%$TOPIC/ms635337_en-us_VS_110_2_0_3_0_0%]>]
[<[%$TOPIC/ms635337_en-us_VS_110_2_0_3_0_1%]>]
type PixelFormats =  class end

The PixelFormats type exposes the following members.

Properties
  NameDescription
Public property Static member Bgr101010Gets the Bgr101010 pixel format. Bgr101010 is a sRGB format with 32 bits per pixel (BPP). Each color channel (blue, green, and red) is allocated 10 bits per pixel (BPP).
Public property Static member Bgr24Gets the Bgr24 pixel format. Bgr24 is a sRGB format with 24 bits per pixel (BPP). Each color channel (blue, green, and red) is allocated 8 bits per pixel (BPP).
Public property Static member Bgr32Gets the Bgr32 pixel format. Bgr32 is a sRGB format with 32 bits per pixel (BPP). Each color channel (blue, green, and red) is allocated 8 bits per pixel (BPP).
Public property Static member Bgr555Gets the Bgr555 pixel format. Bgr555 is a sRGB format with 16 bits per pixel (BPP). Each color channel (blue, green, and red) is allocated 5 bits per pixel (BPP).
Public property Static member Bgr565Gets the Bgr565 pixel format. Bgr565 is a sRGB format with 16 bits per pixel (BPP). Each color channel (blue, green, and red) is allocated 5, 6, and 5 bits per pixel (BPP) respectively.
Public property Static member Bgra32Gets the Bgra32 pixel format. Bgra32 is a sRGB format with 32 bits per pixel (BPP). Each channel (blue, green, red, and alpha) is allocated 8 bits per pixel (BPP).
Public property Static member BlackWhiteGets the black and white pixel format which displays one bit of data per pixel as either black or white.
Public property Static member Cmyk32Gets the Cmyk32 pixel format which displays 32 bits per pixel (BPP) with each color channel (cyan, magenta, yellow, and black) allocated 8 bits per pixel (BPP).
Public property Static member DefaultGets the pixel format that is best suited for the particular operation.
Public property Static member Gray16Gets the Gray16 pixel format which displays a 16 bits-per-pixel grayscale channel, allowing 65536 shades of gray. This format has a gamma of 1.0.
Public property Static member Gray2Gets the Gray2 pixel format which displays a 2 bits-per-pixel grayscale channel, allowing 4 shades of gray.
Public property Static member Gray32FloatGets the Gray32Float pixel format. Gray32Float displays a 32 bits per pixel (BPP) grayscale channel, allowing over 4 billion shades of gray. This format has a gamma of 1.0.
Public property Static member Gray4Gets the Gray4 pixel format which displays a 4 bits-per-pixel grayscale channel, allowing 16 shades of gray.
Public property Static member Gray8Gets the Gray8 pixel format which displays an 8 bits-per-pixel grayscale channel, allowing 256 shades of gray.
Public property Static member Indexed1Gets the pixel format specifying a paletted bitmap with 2 colors.
Public property Static member Indexed2Gets the pixel format specifying a paletted bitmap with 4 colors.
Public property Static member Indexed4Gets the pixel format specifying a paletted bitmap with 16 colors.
Public property Static member Indexed8Gets the pixel format specifying a paletted bitmap with 256 colors.
Public property Static member Pbgra32Gets the Pbgra32 pixel format. Pbgra32 is a sRGB format with 32 bits per pixel (BPP). Each channel (blue, green, red, and alpha) is allocated 8 bits per pixel (BPP). Each color channel is pre-multiplied by the alpha value.
Public property Static member Prgba128FloatGets the Prgba128Float pixel format. Prgba128Float is a ScRGB format with 128 bits per pixel (BPP). Each channel (red, green, blue, and alpha) is allocated 32 bits per pixel (BPP). Each color channel is pre-multiplied by the alpha value. This format has a gamma of 1.0.
Public property Static member Prgba64Gets the Prgba64 pixel format. Prgba64 is a sRGB format with 64 bits per pixel (BPP). Each channel (blue, green, red, and alpha) is allocated 32 bits per pixel (BPP). Each color channel is pre-multiplied by the alpha value. This format has a gamma of 1.0.
Public property Static member Rgb128FloatGets the Rgb128Float pixel format. Rgb128Float is a ScRGB format with 128 bits per pixel (BPP). Each color channel is allocated 32 BPP. This format has a gamma of 1.0.
Public property Static member Rgb24Gets the Rgb24 pixel format. Rgb24 is a sRGB format with 24 bits per pixel (BPP). Each color channel (red, green, and blue) is allocated 8 bits per pixel (BPP).
Public property Static member Rgb48Gets the Rgb48 pixel format. Rgb48 is a sRGB format with 48 bits per pixel (BPP). Each color channel (red, green, and blue) is allocated 16 bits per pixel (BPP). This format has a gamma of 1.0.
Public property Static member Rgba128FloatGets the Rgba128Float pixel format. Rgba128Float is a ScRGB format with 128 bits per pixel (BPP). Each color channel is allocated 32 bits per pixel (BPP). This format has a gamma of 1.0.
Public property Static member Rgba64Gets the Rgba64 pixel format. Rgba64 is an sRGB format with 64 bits per pixel (BPP). Each channel (red, green, blue, and alpha) is allocated 16 bits per pixel (BPP). This format has a gamma of 1.0.
Top
Examples

This example shows how to convert an image to grayscale using FormatConvertedBitmap.

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

  <Page.Resources>

    <!-- This resource defines a BitmapImage with a source and a
         DecodePixelWidth of 200. This property is set to the same value 
         as the desired width of the image to save on memory use. This 
         BitmapImage is used as the base for the other BitmapSource resources. -->
    <BitmapImage x:Key="masterImage" DecodePixelWidth="200" 
     UriSource="C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Forest.jpg"/>

    <!-- This FormatConvertedBitmap uses the BitmapImage defined above and
         changes the format to Gray32Float (grayscale). -->
        <FormatConvertedBitmap x:Key="convertFormatImage" 
                               Source="{StaticResource masterImage}" 
                               DestinationFormat="Gray32Float" />

  </Page.Resources>

  <StackPanel>

    <!-- Apply the "convertFormatImage" resource defined above to this image.  -->
    <Image Width="200" Source="{StaticResource convertFormatImage}" />
  </StackPanel>
</Page>
Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Media
Imports System.Windows.Media.Imaging

Namespace SDKSample

    Class FormatConvertedBitmapExample
        Inherits Page

        Public Sub New()

            '/// Create a BitmapImage and set it's DecodePixelWidth to 200. Use  ///// 
            '/// this BitmapImage as a source for other BitmapSource objects.    ///// 
            Dim myBitmapImage As New BitmapImage()

            ' BitmapSource objects like BitmapImage can only have their properties 
            ' changed within a BeginInit/EndInit block.
            myBitmapImage.BeginInit()
            myBitmapImage.UriSource = New Uri("sampleImages/WaterLilies.jpg", UriKind.Relative)

            ' To save significant application memory, set the DecodePixelWidth or   
            ' DecodePixelHeight of the BitmapImage value of the image source to the desired  
            ' height or width of the rendered image. If you don't do this, the application will  
            ' cache the image as though it were rendered as its normal size rather then just  
            ' the size that is displayed. 
            ' Note: In order to preserve aspect ratio, set DecodePixelWidth 
            ' or DecodePixelHeight but not both.
            myBitmapImage.DecodePixelWidth = 200
            myBitmapImage.EndInit()

            '//////// Convert the BitmapSource to a new format //////////// 
            ' Use the BitmapImage created above as the source for a new BitmapSource object 
            ' which is set to a gray scale format using the FormatConvertedBitmap BitmapSource.                                                
            ' Note: New BitmapSource does not cache. It is always pulled when required. 
            Dim newFormatedBitmapSource As New FormatConvertedBitmap()

            ' BitmapSource objects like FormatConvertedBitmap can only have their properties 
            ' changed within a BeginInit/EndInit block.
            newFormatedBitmapSource.BeginInit()

            ' Use the BitmapSource object defined above as the source for this new  
            ' BitmapSource (chain the BitmapSource objects together).
            newFormatedBitmapSource.Source = myBitmapImage

            ' Set the new format to Gray32Float (grayscale).
            newFormatedBitmapSource.DestinationFormat = PixelFormats.Gray32Float
            newFormatedBitmapSource.EndInit()

            ' Create Image Element 
            Dim myImage As New Image()
            myImage.Width = 200
            'set image source
            myImage.Source = newFormatedBitmapSource

            ' Add Image to the UI 
            Dim myStackPanel As New StackPanel()
            myStackPanel.Children.Add(myImage)
            Me.Content = myStackPanel

        End Sub 'New 
    End Class 'FormatConvertedBitmapExample
End Namespace 'ImagingSnippetGallery
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace SDKSample
{
    public partial class FormatConvertedBitmapExample : Page
    {
        public FormatConvertedBitmapExample()
        {

            ///// Create a BitmapImage and set it's DecodePixelWidth to 200. Use  ///// 
            ///// this BitmapImage as a source for other BitmapSource objects.    /////

            BitmapImage myBitmapImage = new BitmapImage();

            // BitmapSource objects like BitmapImage can only have their properties 
            // changed within a BeginInit/EndInit block.
            myBitmapImage.BeginInit();
            myBitmapImage.UriSource = new Uri(@"sampleImages/WaterLilies.jpg",UriKind.Relative);

            // To save significant application memory, set the DecodePixelWidth or   
            // DecodePixelHeight of the BitmapImage value of the image source to the desired  
            // height or width of the rendered image. If you don't do this, the application will  
            // cache the image as though it were rendered as its normal size rather then just  
            // the size that is displayed. 
            // Note: In order to preserve aspect ratio, set DecodePixelWidth 
            // or DecodePixelHeight but not both.
            myBitmapImage.DecodePixelWidth = 200;
            myBitmapImage.EndInit();

            ////////// Convert the BitmapSource to a new format //////////// 
            // Use the BitmapImage created above as the source for a new BitmapSource object 
            // which is set to a gray scale format using the FormatConvertedBitmap BitmapSource.                                                
            // Note: New BitmapSource does not cache. It is always pulled when required.

            FormatConvertedBitmap newFormatedBitmapSource = new FormatConvertedBitmap();

            // BitmapSource objects like FormatConvertedBitmap can only have their properties 
            // changed within a BeginInit/EndInit block.
            newFormatedBitmapSource.BeginInit();

            // Use the BitmapSource object defined above as the source for this new  
            // BitmapSource (chain the BitmapSource objects together).
            newFormatedBitmapSource.Source = myBitmapImage;

            // Set the new format to Gray32Float (grayscale).
            newFormatedBitmapSource.DestinationFormat = PixelFormats.Gray32Float;
            newFormatedBitmapSource.EndInit();

            // Create Image Element
            Image myImage = new Image();
            myImage.Width = 200;
            //set image source
            myImage.Source = newFormatedBitmapSource;

            // Add Image to the UI
            StackPanel myStackPanel = new StackPanel();
            myStackPanel.Children.Add(myImage);
            this.Content = myStackPanel;
        }
    }
}
Version Information

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

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.

Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.