我創建了一個WPF應用程序,所以我主要使用圖標的ImageSource類。但是,系統托盤圖標必須爲System.Drawing.Icon
。是否可以從PNG圖像創建這樣的對象?如何從PNG圖像獲取圖標?
我曾嘗試以下:
private static System.Drawing.Icon _pngIcon;
public static System.Drawing.Icon PngIcon
{
get
{
if (_pngIcon == null)
{
//16x16 png image (24 bit or 32bit color)
System.Drawing.Bitmap icon = global::BookyPresentation.Properties.Resources.star16;
MemoryStream iconStream = new MemoryStream();
icon.Save(iconStream, System.Drawing.Imaging.ImageFormat.Png);
iconStream.Seek(0, SeekOrigin.Begin);
_pngIcon = new System.Drawing.Icon(iconStream); //Throws exception
}
return _pngIcon;
}
}
圖標構造函數拋出具有以下消息的異常:「論證‘圖像’必須是可以被用作圖標的圖片。」
我想它可能是圖像顏色的位深度的東西,因爲我之前有過一些問題,但32位和24位圖像都不起作用。我想要做什麼?
當我使用這種方法時,我只能得到16個顏色圖標 – 2009-11-04 13:06:08