1

我需要用 C# 中的封面艺术标记 MP3 文件...

有什么简单的方法可以做到这一点吗?我发现 UltraID3Lib 作为示例,它非常适合常规 ID3 标记,但我无法处理封面。如果有人知道这样做的简单方法会很棒:)

4

1 回答 1

2

我做这样的事情

private static void FixAlbumArt(FileInfo MyFile)
{
  //Find the jpeg file in the directory of the Mp3 File
  //We will embed this image into the ID3v2 tag
  FileInfo[] fiAlbumArt = MyFile.Directory.GetFiles("*.jpg");
  if (fiAlbumArt.Length < 1)
  {
    Console.WriteLine("No Album Art Found in {0}", MyFile.Directory.Name);
    return;
  }
  string AlbumArtFile = fiAlbumArt[0].FullName;

  //Create Mp3 Object
  UltraID3 myMp3 = new UltraID3();
  myMp3.Read(MyFile.FullName);
  ID3FrameCollection myArtworkCollection =
    myMp3.ID3v23Tag.Frames.GetFrames(MultipleInstanceFrameTypes.Picture);

  if (myArtworkCollection.Count > 0)
  {//Get Rid of the Bad Embedded Artwork
    #region Remove All Old Artwork
    for (int i = 0; i < myArtworkCollection.Count; i++)
    {
      ID3PictureFrame ra = (ID3PictureFrame)myArtworkCollection[0];
      try
      {
        myMp3.ID3v23Tag.Frames.Remove(FrameTypes.Picture);
      }
      catch { }
    }
    myArtworkCollection.Clear();

     //Save out our changes so that we are working with the
    //most up to date file and tags
    myMp3.ID3v23Tag.WriteFlag = true;
    myMp3.Write();
    myMp3.Read(MyFile.FullName);
    #endregion Remove All Old Artwork
  }
  //Create a PictureFrame object, pointing it at the image on my PC
  ID3PictureFrame AlbumArt =
    new ID3PictureFrame(
    (System.Drawing.Bitmap)System.Drawing.Bitmap.FromFile(AlbumArtFile),
    PictureTypes.CoverFront, "Attached picture", TextEncodingTypes.ISO88591);
  myMp3.ID3v23Tag.Frames.Add(AlbumArt);
  myMp3.ID3v23Tag.WriteFlag = true;
  myMp3.Write();

  myMp3 = null;
}

我在工作,忘记打开 Foldershare,所以我无法向您展示我的精简版本,我在其中传递了一个 Image 对象,但这拥有完成工作所需的一切。祝你好运。

于 2008-12-08T14:03:54.917 回答