2

我想在图像控件中显示一个图标,我该怎么做。

System.Drawing.Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(@"C:\Users\bgh32648\Desktop\Filename.extension");

Image Img = new Image();

我想将图标分配给 img

4

1 回答 1

3
public static ImageSource ToImageSource(this Icon icon)
{
    ImageSource imageSource = Imaging.CreateBitmapSourceFromHIcon(
        icon.Handle,
        Int32Rect.Empty,
        BitmapSizeOptions.FromEmptyOptions());

    return imageSource;
}

进而image.Source = icon.ToImageSource();

于 2013-10-28T07:06:36.700 回答