How do you add a picture to the ID3 Album tag using taglib#

555 Views Asked by At

I've been searching the internet and trying various methods to save a picturbox image to the the id3 Album picture tag. One sample code says the Album cover tag name is taglib.ipicture another says taglibVariable.Image and yet another says taglibVariable.picture(0). I am becoming so confused I'm starting to repeat sample test code. Where is the documentation that will explain what I have to do.? What little information I can find are dead links to sample code or incomplete code using variables without explanations. When I look up the commands and try to format or convert to the needed data type, I get an error. Usually system.image.bmp cannot be converted to iPicture.

Can anyone give me some working code or a pointer on how to word the proper search term to add a picturebox.image to the Album picture tag. Saving the image as a file then opening as image to put in tag then deleting file is not an option. I need to create a memory image and add that to the picture tag.

1

There are 1 best solutions below

0
Paul B On

This is what I use:

public void SavePicture(string fileName, string picName) {
      try {
        IPicture[] pics = new TagLib.IPicture[1];
        pics[0] = new TagLib.Picture(picName);
        using (var songTag = TagLib.File.Create(fileName)) {
          songTag.Tag.Pictures = pics;
          songTag.Save();
        }
      }
      catch {
        // process
        // mpeg header is corrupt
      }
    }

fileName is the full path to the audio file;

picName is the full path to the picture.

You can add multiple pics by setting the array size for the IPicture array accordingly...