C#中的MP3封面艺术标签

时间:2008-12-08 13:41:09

标签: c# tags mp3 cover

我需要用C#封面艺术标记MP3文件... ...
有没有简单的方法来做到这一点?我发现UltraID3Lib作为一个例子,它非常适合常规ID3标记但我无法处理封面艺术。如果有人知道一个简单的方法,这将是伟大的:)

1 个答案:

答案 0 :(得分:2)

我做this之类的事情:

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对象时修剪过的版本,但是这里有你需要做的所有事情来完成一些黑客攻击。祝你好运。