BitmapPalette 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
定義支援影像類型的可用色彩調色盤。
public ref class BitmapPalette sealed : System::Windows::Threading::DispatcherObject
public sealed class BitmapPalette : System.Windows.Threading.DispatcherObject
type BitmapPalette = class
inherit DispatcherObject
Public NotInheritable Class BitmapPalette
Inherits DispatcherObject
- 繼承
範例
以下範例示範如何定義自訂 BitmapPalette 並套用於新的 BitmapSource。
int width = 128;
int height = width;
int stride = width/8;
byte[] pixels = new byte[height*stride];
// Try creating a new image with a custom palette.
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);
colors.Add(System.Windows.Media.Colors.Green);
BitmapPalette myPalette = new BitmapPalette(colors);
// 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("empty.tif", FileMode.Create);
TiffBitmapEncoder encoder = new TiffBitmapEncoder();
TextBlock myTextBlock = new TextBlock();
myTextBlock.Text = "Codec Author is: " + encoder.CodecInfo.Author.ToString();
encoder.Frames.Add(BitmapFrame.Create(image));
MessageBox.Show(myPalette.Colors.Count.ToString());
encoder.Save(stream);
Dim width As Integer = 128
Dim height As Integer = width
Dim stride As Integer = CType(width / 8, Integer)
Dim pixels(height * stride) As Byte
' Try creating a new image with a custom palette.
Dim colors As New List(Of System.Windows.Media.Color)()
colors.Add(System.Windows.Media.Colors.Red)
colors.Add(System.Windows.Media.Colors.Blue)
colors.Add(System.Windows.Media.Colors.Green)
Dim myPalette As New BitmapPalette(colors)
' 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("empty.tif", FileMode.Create)
Dim encoder As New TiffBitmapEncoder()
Dim myTextBlock As New TextBlock()
myTextBlock.Text = "Codec Author is: " + encoder.CodecInfo.Author.ToString()
encoder.Frames.Add(BitmapFrame.Create(image))
MessageBox.Show(myPalette.Colors.Count.ToString())
encoder.Save(stream)
以下範例示範如何從影像中取得 a BitmapPalette 。
// Get the palette from an image
BitmapImage image2 = new BitmapImage();
image2.BeginInit();
image2.UriSource = new Uri("tulipfarm.tif", UriKind.RelativeOrAbsolute);
image2.EndInit();
BitmapPalette myPalette3 = new BitmapPalette(image2, 256);
//Draw the third Image
Image myImage2 = new Image();
myImage2.Source = image2;
myImage2.Stretch = Stretch.None;
myImage2.Margin = new Thickness(20);
' Get the palette from an image
Dim image2 As New BitmapImage()
image2.BeginInit()
image2.UriSource = New Uri("tulipfarm.tif", UriKind.RelativeOrAbsolute)
image2.EndInit()
Dim myPalette3 As New BitmapPalette(image2, 256)
'Draw the third Image
Dim myImage2 As New Image()
myImage2.Source = image2
myImage2.Stretch = Stretch.None
myImage2.Margin = New Thickness(20)
備註
只有標籤影像檔案格式(TIFF)和圖形交換格式(GIF)支援影像調色盤。 然而,其他影像類型可用來定義 BitmapPalette。 嘗試為不支援的點陣圖格式定義 a BitmapPalette 並不會產生例外;指定 BitmapPalette 該 API 會被忽略。
Windows Presentation Foundation(WPF)支援自訂調色盤及由 BitmapPalettes 類別定義的調色盤。
建構函式
| 名稱 | Description |
|---|---|
| BitmapPalette(BitmapSource, Int32) |
根據指定的 BitmapPalette初始化類別的新實例BitmapSource。 新版本 BitmapPalette 的顏色數量限制在指定的最大數量內。 |
| BitmapPalette(IList<Color>) |
初始化一個新的類別實例 BitmapPalette ,並以指定顏色。 |
屬性
| 名稱 | Description |
|---|---|
| Colors |
把顏色定義在調色盤裡。 |
| Dispatcher |
了解 Dispatcher 這與此 DispatcherObject 有關。 (繼承來源 DispatcherObject) |
方法
| 名稱 | Description |
|---|---|
| CheckAccess() |
判斷呼叫執行緒是否能存取此 DispatcherObject。 (繼承來源 DispatcherObject) |
| Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
| GetHashCode() |
做為預設哈希函式。 (繼承來源 Object) |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| ToString() |
傳回表示目前 物件的字串。 (繼承來源 Object) |
| VerifyAccess() |
強制呼叫執行緒能存取此 DispatcherObject。 (繼承來源 DispatcherObject) |