我想在Image控件中显示一个图标,我该怎么做。
System.Drawing.Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(@"C:\Users\bgh32648\Desktop\Filename.extension");
Image Img = new Image();
我想将图标分配给img
答案 0 :(得分:3)
public static ImageSource ToImageSource(this Icon icon)
{
ImageSource imageSource = Imaging.CreateBitmapSourceFromHIcon(
icon.Handle,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
return imageSource;
}
然后image.Source = icon.ToImageSource();