Using taglib to display the cover art in a Image box in WPF

前端 未结 1 1816
天涯浪人
天涯浪人 2021-01-03 13:59

I\'m making a player and I\'m stuck in a apparently simple problem. I need to make the cover art of the song to be displayed in one Image box. I found these two solutions:

相关标签:
1条回答
  • 2021-01-03 14:34

    Use System.Windows.Controls.Image to display your images on UI. You must set it's Source property in order to provide image data to render on UI.

    // Load you image data in MemoryStream
    TagLib.IPicture pic = f.Tag.Pictures[0];
    MemoryStream ms = new MemoryStream(pic.Data.Data);
    ms.Seek(0, SeekOrigin.Begin);
    
    // ImageSource for System.Windows.Controls.Image
    BitmapImage bitmap= new BitmapImage();
    bitmap.BeginInit();
    bitmap.StreamSource = ms;
    bitmap.EndInit();
    
    // Create a System.Windows.Controls.Image control
    System.Windows.Controls.Image img = new System.Windows.Controls.Image();
    img.Source = bitmap;
    

    Then you can add/place this Image control to UI.

    0 讨论(0)
提交回复
热议问题