Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
 DestinationPalette Property
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
FormatConvertedBitmap..::.DestinationPalette Property

Gets or sets the palette to apply to the bitmap if the format is indexed. This is a dependency property.

Namespace:  System.Windows.Media.Imaging
Assembly:  PresentationCore (in PresentationCore.dll)
Visual Basic (Declaration)
Public Property DestinationPalette As BitmapPalette
Visual Basic (Usage)
Dim instance As FormatConvertedBitmap
Dim value As BitmapPalette

value = instance.DestinationPalette

instance.DestinationPalette = value
C#
public BitmapPalette DestinationPalette { get; set; }
Visual C++
public:
property BitmapPalette^ DestinationPalette {
    BitmapPalette^ get ();
    void set (BitmapPalette^ value);
}
JScript
public function get DestinationPalette () : BitmapPalette
public function set DestinationPalette (value : BitmapPalette)
XAML
You cannot set this property in XAML.

Property Value

Type: System.Windows.Media.Imaging..::.BitmapPalette
The destination palette to apply to the bitmap. The default value is nullNothingnullptra null reference (Nothing in Visual Basic).

Identifier field

DestinationPaletteProperty

Metadata properties set to true

None

You must set this property if you want to use an indexed pixel format for the DestinationFormat.

This example shows how to convert a BitmapSource to an indexed pixel format.

Visual Basic
Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Imports System.Collections.Generic

Namespace SDKSample

    Class FormatConvertedBitmapExample2
        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 two color pixel 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

            ' Because the DestinationFormat for the FormatConvertedBitmap will be an
            ' indexed pixel format (Indexed1),a DestinationPalette also needs to be specified.
            ' Below, create a custom two color palette to be used for the DestinationPalette.
            Dim colors As New List(Of Color)
            colors.Add(System.Windows.Media.Colors.Red)
            colors.Add(System.Windows.Media.Colors.Blue)
            Dim myPalette As New BitmapPalette(colors)

            ' Set the DestinationPalette property to the custom palette created above.
            newFormatedBitmapSource.DestinationPalette = myPalette

            ' Set the DestinationFormat to the palletized pixel format of Indexed1.
            newFormatedBitmapSource.DestinationFormat = PixelFormats.Indexed1
            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 'FormatConvertedBitmapExample2
End Namespace 'ImagingSnippetGallery
C#
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Collections.Generic;
namespace SDKSample
{
    public partial class FormatConvertedBitmapExample2 : Page
    {
        public FormatConvertedBitmapExample2()
        {

            ///// 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 two color pixel 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;

            // Because the DestinationFormat for the FormatConvertedBitmap will be an
            // indexed pixel format (Indexed1),a DestinationPalette also needs to be specified.
            // Below, create a custom two color palette to be used for the DestinationPalette.
            List<System.Windows.Media.Color> colors = new List<System.Windows.Media.Color>();
            colors.Add(System.Windows.Media.Colors.Red);
            colors.Add(System.Windows.Media.Colors.Blue);
            BitmapPalette myPalette = new BitmapPalette(colors);

            // Set the DestinationPalette property to the custom palette created above.
            newFormatedBitmapSource.DestinationPalette = myPalette;

            // Set the DestinationFormat to the palletized pixel format of Indexed1.
            newFormatedBitmapSource.DestinationFormat = PixelFormats.Indexed1;
            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;
        }
    }
}

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.

.NET Framework

Supported in: 3.5, 3.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 | Site Feedback
Page view tracker