Application/C# (WPF)

[C# WPF] 파일의 아이콘을 추출해서 BitmapImage 변환하기

devsalix 2023. 1. 10. 16:53
728x90
반응형

특정 파일의 아이콘을 추출하여 BitampImage로 변환을 하기 위해서는

 

아래와 같은 함수를 사용하면 됩니다

 

 private BitmapImage LoadIcon(string filename)
{
    Icon ico = System.Drawing.Icon.ExtractAssociatedIcon(filename);
    Bitmap bmp = ico.ToBitmap();

    MemoryStream ms = new MemoryStream();
    bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);

    BitmapImage bi = new BitmapImage();
    bi.BeginInit();
    bi.StreamSource = ms;
    bi.CacheOption = BitmapCacheOption.OnLoad;
    bi.EndInit();

    return bi;
}
728x90
반응형