1

MP3 のカバー アートとしてビットマップを設定しようとしていますが、うまく動作しないようです。エラーは発生していませんが、MP3 を再生するとビットマップが表示されません。

これは私が現在持っているものです:

TagLib.File f = TagLib.File.Create("song.mp3");

Image currentImage = getAlbumArt(result.passedAlbumID);
Picture pic = new Picture();
pic.Type = PictureType.FrontCover;
pic.MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg;
pic.Description = "Cover";
MemoryStream ms = new MemoryStream();
currentImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
ms.Position = 0;
pic.Data = ByteVector.FromStream(ms);
f.Tag.Pictures = new IPicture[1] { pic };
pictureBox1.Image = currentImage; //testing the image is correct

f.Save();
ms.Close();
4

1 に答える 1

7

私は次のコードを使用していますが、すべてうまくいきます。

TagLib.File file = TagLib.File.Create(/*path to your mp3 file*/);
TagLib.Picture pic = new TagLib.Picture();
pic.Type = TagLib.PictureType.FrontCover;
pic.Description = "Cover";
pic.MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg;
MemoryStream ms = new MemoryStream();
/*your image*/.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
ms.Position = 0;
pic.Data = TagLib.ByteVector.FromStream(ms);
file.Tag.Pictures = new TagLib.IPicture[] { pic };
file.Save();
ms.Close();

提供されたコードによると、私が気付いた唯一のことは、私のコードが次の行を使用していることです

file.Tag.Pictures = new TagLib.IPicture[] { pic };

それ以外の

f.Tag.Pictures = new TagLib.IPicture[1] { pic };

1角かっこの内側を削除すると機能する場合は、単純に試してください。

于 2015-05-17T09:08:34.583 に答える