I found a way to do it with my own code without needing the Tags Library. We can disregard this post.
So this is regarding the Tags Library add on, not the Tags add on that is on the main page. I went to post in the original thread but it said it had been over a year since any replies and I should make a new post. Hopefully the developer sees this.
I'm trying to attach album art to ogg output files. I got all other metadata down with Bass and its add-ons, but don't see a way to set the album art. Tags Library seems to do it, but I keep getting a memory error no matter what I try. And I have tried quite a bit over the last 3-4 hours of non stop variations of code.
So I'm hoping the developer or someone with more experience can tell me what I'm doing wrong. This is the relevant C# code:
if (out_ext == "ogg" && File.Exists(art))
{
var Tags = TagsLib.TagsLibrary_Create();
TagsLib.TagsLibrary_Load(Tags, output, TTagType.ttOpusVorbis, true);
if (Tags.HTags != IntPtr.Zero)
{
var imgBytes = File.ReadAllBytes(art);
var img = Image.FromFile(art);
var coverArt = new TCoverArtData();
coverArt.Index = 0;
if (ImageFormat.Png.Equals(img.RawFormat))
{
coverArt.PictureFormat = TTagPictureFormat.tpfPNG;
coverArt.MIMETypeSPtr = Marshal.StringToHGlobalAuto("image/png");
}
else if (ImageFormat.Bmp.Equals(img.RawFormat))
{
coverArt.PictureFormat = TTagPictureFormat.tpfBMP;
coverArt.MIMETypeSPtr = Marshal.StringToHGlobalAuto("image/bmp");
}
else if (ImageFormat.Gif.Equals(img.RawFormat))
{
coverArt.PictureFormat = TTagPictureFormat.tpfGIF;
coverArt.MIMETypeSPtr = Marshal.StringToHGlobalAuto("image/gif");
}
else
{
coverArt.PictureFormat = TTagPictureFormat.tpfJPEG;
coverArt.MIMETypeSPtr = Marshal.StringToHGlobalAuto("image/jpeg");
}
coverArt.Width = img.Width;
coverArt.Height = img.Height;
switch (img.PixelFormat)
{
case PixelFormat.Format1bppIndexed:
coverArt.ColorDepth = 1;
break;
case PixelFormat.Format4bppIndexed:
coverArt.ColorDepth = 4;
break;
case PixelFormat.Format8bppIndexed:
coverArt.ColorDepth = 8;
break;
case PixelFormat.Format16bppGrayScale:
case PixelFormat.Format16bppRgb555:
case PixelFormat.Format16bppRgb565:
case PixelFormat.Format16bppArgb1555:
coverArt.ColorDepth = 16;
break;
case PixelFormat.Format32bppRgb:
case PixelFormat.Format32bppArgb:
case PixelFormat.Format32bppPArgb:
coverArt.ColorDepth = 32;
break;
case PixelFormat.Format24bppRgb:
default:
coverArt.ColorDepth = 24;
break;
}
coverArt.NoOfColors = 0;
coverArt.CoverType = TCoverTypes.ctCoverFront;
IntPtr imagePtr = TagsLib_API.Utils.Utils.GetPointerfromByteArray(imgBytes);
coverArt.Data = imagePtr;
long length = 0;
using (MemoryStream memoryStream = new MemoryStream())
{
if (ImageFormat.Png.Equals(img.RawFormat))
{
img.Save(memoryStream, ImageFormat.Png);
}
else if (ImageFormat.Bmp.Equals(img.RawFormat))
{
img.Save(memoryStream, ImageFormat.Bmp);
}
else if (ImageFormat.Gif.Equals(img.RawFormat))
{
img.Save(memoryStream, ImageFormat.Gif);
}
else
{
img.Save(memoryStream, ImageFormat.Jpeg);
}
length = memoryStream.Length;
}
coverArt.DataSize = length;
try
{
TagsLib.TagsLibrary_AddCoverArt(Tags, TTagType.ttOpusVorbis, coverArt);
}
finally
{
TagsLib.TagsLibrary_Free(Tags);
}
}
The memory error always happens at this line:
TagsLib.TagsLibrary_AddCoverArt(Tags, TTagType.ttOpusVorbis, coverArt);
So there's something I'm missing.
Any help is appreciated. Thanks!
EDIT:
I've also tried:
TagsLib.TagsLibrary_SetCoverArt(Tags, TTagType.ttOpusVorbis, 0, ref coverArt);
and
TagsLib.TagsLibrary_SetCoverArtFromFile(Tags, TTagType.ttOpusVorbis, 0, art, coverArt);
Both of those proceed without any error but they do not save the album art to the resulting file. Maybe I'm missing a step there or I'm doing it wrong too. At least there's no memory error.[/s]