保存图片时Taglib NullException

时间:2018-03-31 07:43:29

标签: c# taglib

我正在使用自己的标签编辑器来处理Mp3文件。到目前为止,我一直很好,直到我把图片保存到文件中。所以我做了一些搜索并发现了这两种方法,但是当我按下我的程序上的保存按钮时,NullException发生了TagLib.Picture pic = TagLib.Picture.CreateFromPath(PicDir); //occurs here TagLib.Id3v2.AttachedPictureFrame albumCoverPictFrame = new TagLib.Id3v2.AttachedPictureFrame(pic); albumCoverPictFrame.MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg; albumCoverPictFrame.Type = TagLib.PictureType.FrontCover; TagLib.IPicture[] pictFrames = new IPicture[1]; pictFrames[0] = (IPicture)albumCoverPictFrame; file.Tag.Pictures = pictFrames; ,并且“值不能为空”这里是两个代码:

System.Drawing.Image img = System.Drawing.Image.FromFile(PicDir); //occurs here
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();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
ms.Position = 0;
pic.Data = TagLib.ByteVector.FromStream(ms);
file.Tag.Pictures = new TagLib.IPicture[] { pic };
ms.Close();

和这一个:

NullException

我在互联网上找不到关于使用TagLib保存图片showDialog的任何内容。我确定图片目录或图片本身没有任何问题,所以问题来自其他地方。

这是我使用private void OpenPic_Click(object sender, EventArgs e) { openFileDialog3.DefaultExt = "JPG"; openFileDialog3.Filter = "JPEG Files (*.jpg)|*.jpg"; openFileDialog3.Multiselect = false; openFileDialog3.FileName = "Choose the Photo"; openFileDialog3.ShowDialog(); }

的部分
FileOk

这是private void Pic_FileOk(object sender, CancelEventArgs e) { label21.Visible = true; PicDir = openFileDialog3.FileName; Aks = true; } 部分:

<h1> View </h1>
<?php if(!empty($this->session->given_name)){?>
    <li><a href="#">Hi <?= $this->session->given_name;?></a></li>
<?php }

0 个答案:

没有答案