1.下载软件:
点击下载批量添加歌曲封面软件
2.解压软件
下载之后点击解压软件,双击打开Mp3AddCover.exe。
3.使用说明
1.添加歌曲(mp3格式)所在文件夹
2.添加封面(jpg格式)所在文件夹
3.点击“添加封面”按钮开始自动匹配歌曲封面
Ps:保持歌曲和封面名一致
4.主要代码
需要添加nuget包:
/// <summary>
/// 给歌曲添加封面
/// </summary>
/// <param name="coverPath">封面路径</param>
/// <param name="filePath">歌曲路径</param>
/// <param name="isReplace">是否替换当前mp3文件原有的封面</param>
public static void SetAlbumArt(string coverPath, string filePath, bool isReplace)
{var fileInfo = new FileInfo(filePath);Stream stream = fileInfo.Open(FileMode.Open);var abstraction = new TagLib.StreamFileAbstraction(fileInfo.Name, stream, stream);var file = TagLib.File.Create(abstraction);var picture = file.Tag.Pictures;if (picture.Length > 0 && !isReplace){return;}Picture pic = new Picture(){Type = PictureType.FrontCover,Description = "Cover",MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg};Image image = Image.FromFile(coverPath);MemoryStream ms = new MemoryStream();image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);ms.Position = 0;pic.Data = ByteVector.FromStream(ms);file.Tag.Pictures = new IPicture[] { pic };file.Save();file.Dispose();
}