I'm Working on my own tag editor for Mp3 files. It's been good so far until I got stuck on saving the picture to the file. So I did a little searching and found out about these two ways but in both of them when I press the save button on my program a NullException
occurs and says "value cannot be null" here are the two codes:
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;
and this one:
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();
I can't find anything on Internet about a NullException
on saving the pic with TagLib. I'm sure nothing is wrong with the picture directory or the picture itself, so the problem comes from elsewhere.
This is the part where I use 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();
}
and here is the FileOk
part:
private void Pic_FileOk(object sender, CancelEventArgs e)
{
label21.Visible = true;
PicDir = openFileDialog3.FileName;
Aks = true;
}