Example #1
0
        public unsafe void LoadCurrentCovers()
        {
            for (int i = 0; i < TagsInfo.PictureCount; i++)
            {
                TagPicture coverBASS = TagsInfo.PictureGet(i);
                Image image = coverBASS.PictureImage;
                TCoverArtData CoverArtData = new TCoverArtData();

                TCoverTypes CoverTypes = TCoverTypes.ctOther;
                string MIMEType = coverBASS.MIMEType;
                string Description = coverBASS.Description;
                int Width = image.Width;
                int Height = image.Height;
                int ColorDepth = 0;
                int NoOfColors = 0;
                TTagPictureFormat CoverArtPictureFormat = TTagPictureFormat.tpfUnknown;

                switch (coverBASS.PictureType)
                {
                    case TagPicture.PICTURE_TYPE.Artists:
                        CoverTypes = TCoverTypes.ctArtist;
                        break;
                    case TagPicture.PICTURE_TYPE.BandLogo:
                        CoverTypes = TCoverTypes.ctBandLogo;
                        break;
                    case TagPicture.PICTURE_TYPE.Composer:
                        CoverTypes = TCoverTypes.ctComposer;
                        break;
                    case TagPicture.PICTURE_TYPE.Conductor:
                        CoverTypes = TCoverTypes.ctConductor;
                        break;
                    case TagPicture.PICTURE_TYPE.FrontAlbumCover:
                        CoverTypes = TCoverTypes.ctCoverFront;
                        break;
                    case TagPicture.PICTURE_TYPE.BackAlbumCover:
                        CoverTypes = TCoverTypes.ctCoverback;
                        break;
                    case TagPicture.PICTURE_TYPE.Icon32:
                        CoverTypes = TCoverTypes.ctIcon;
                        break;
                    case TagPicture.PICTURE_TYPE.Illustration:
                        CoverTypes = TCoverTypes.ctIllustration;
                        break;
                    case TagPicture.PICTURE_TYPE.LeadArtist:
                        CoverTypes = TCoverTypes.ctLead;
                        break;
                    case TagPicture.PICTURE_TYPE.LeafletPage:
                        CoverTypes = TCoverTypes.ctLeaflet;
                        break;
                    case TagPicture.PICTURE_TYPE.OtherIcon:
                        CoverTypes = TCoverTypes.ctOtherIcon;
                        break;
                    case TagPicture.PICTURE_TYPE.Performance:
                        CoverTypes = TCoverTypes.ctPerformance;
                        break;
                    case TagPicture.PICTURE_TYPE.PublisherLogo:
                        CoverTypes = TCoverTypes.ctPublisher;
                        break;
                    case TagPicture.PICTURE_TYPE.Location:
                        CoverTypes = TCoverTypes.ctRecordingLocation;
                        break;
                    case TagPicture.PICTURE_TYPE.VideoCapture:
                        CoverTypes = TCoverTypes.ctMovie;
                        break;
                    case TagPicture.PICTURE_TYPE.ColoredFish:
                        CoverTypes = TCoverTypes.ctcoloured;
                        break;
                    case TagPicture.PICTURE_TYPE.Orchestra:
                        CoverTypes = TCoverTypes.ctBand;
                        break;
                    case TagPicture.PICTURE_TYPE.RecordingSession:
                        CoverTypes = TCoverTypes.ctDuringRecording;
                        break;
                    case TagPicture.PICTURE_TYPE.Unknown:
                        CoverTypes = TCoverTypes.ctOther;
                        break;
                    case TagPicture.PICTURE_TYPE.Writer:
                        CoverTypes = TCoverTypes.ctLyricist;
                        break;
                    case TagPicture.PICTURE_TYPE.Media:
                        CoverTypes = TCoverTypes.ctLabel;
                        break;
                }

                if (image.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Jpeg))
                {
                    CoverArtPictureFormat = TTagPictureFormat.tpfJPEG;
                    ColorDepth = 24;
                }
                else if (image.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Png))
                {
                    CoverArtPictureFormat = TTagPictureFormat.tpfPNG;
                    ColorDepth = Image.GetPixelFormatSize(image.PixelFormat);
                }
                else if (image.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Gif))
                {
                    CoverArtPictureFormat = TTagPictureFormat.tpfGIF;
                    ColorDepth = Image.GetPixelFormatSize(image.PixelFormat);
                }
                else if (image.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Bmp))
                {
                    CoverArtPictureFormat = TTagPictureFormat.tpfBMP;
                    ColorDepth = Image.GetPixelFormatSize(image.PixelFormat);
                }

                var ms = new MemoryStream();
                image.Save(ms, image.RawFormat);
                byte[] imageToByteArray = ms.ToArray();

                fixed (byte* p = imageToByteArray)
                {
                    IntPtr imgPtr = (IntPtr)p;

                    CoverArtData.NameSPtr = Marshal.StringToHGlobalAuto(Description);
                    CoverArtData.CoverType = CoverTypes;
                    CoverArtData.MIMETypeSPtr = Marshal.StringToHGlobalAuto(MIMEType);
                    CoverArtData.DescriptionSPtr = Marshal.StringToHGlobalAuto(Description);
                    CoverArtData.Width = Width;
                    CoverArtData.Height = Height;
                    CoverArtData.ColorDepth = ColorDepth;
                    CoverArtData.NoOfColors = NoOfColors;
                    CoverArtData.PictureFormat = CoverArtPictureFormat;
                    CoverArtData.Data = imgPtr;
                    CoverArtData.DataSize = ms.Length;

                    Pictures.Add(CoverArtData);
                    //TagsLib.TagsLibrary_AddCoverArt(HTags, TTagType.ttAutomatic, CoverArtData);
                    ms.Close();
                }
            }
        }
Example #2
0
        public unsafe void LoadCoversInFile(Image image)
        {
            string MIMEType = "";
            string Description = "";
            int Width = image.Width;
            int Height = image.Height;
            int ColorDepth = 0;
            int NoOfColors = 0;

            TCoverArtData CoverArtData = new TCoverArtData();
            TTagPictureFormat CoverArtPictureFormat = TTagPictureFormat.tpfUnknown;

            if (image.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Jpeg))
            {
                MIMEType = "image/jpeg";
                CoverArtPictureFormat = TTagPictureFormat.tpfJPEG;
                ColorDepth = 24;
            }
            else if (image.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Png))
            {
                MIMEType = "image/png";
                CoverArtPictureFormat = TTagPictureFormat.tpfPNG;
                ColorDepth = Image.GetPixelFormatSize(image.PixelFormat);
            }
            else if (image.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Gif))
            {
                MIMEType = "image/gif";
                CoverArtPictureFormat = TTagPictureFormat.tpfGIF;
                ColorDepth = Image.GetPixelFormatSize(image.PixelFormat);
            }
            else if (image.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Bmp))
            {
                MIMEType = "image/bmp";
                CoverArtPictureFormat = TTagPictureFormat.tpfBMP;
                ColorDepth = Image.GetPixelFormatSize(image.PixelFormat);
            }

            var ms = new MemoryStream();
            image.Save(ms, image.RawFormat);
            byte[] imageToByteArray = ms.ToArray();

            fixed (byte* p = imageToByteArray)
            {
                IntPtr imgPtr = (IntPtr)p;

                CoverArtData.NameSPtr = Marshal.StringToHGlobalAuto(Description);
                CoverArtData.CoverType = TCoverTypes.ctCoverFront;
                CoverArtData.MIMETypeSPtr = Marshal.StringToHGlobalAuto(MIMEType);
                CoverArtData.DescriptionSPtr = Marshal.StringToHGlobalAuto(Description);
                CoverArtData.Width = Width;
                CoverArtData.Height = Height;
                CoverArtData.ColorDepth = ColorDepth;
                CoverArtData.NoOfColors = NoOfColors;
                CoverArtData.PictureFormat = CoverArtPictureFormat;
                CoverArtData.Data = imgPtr;
                CoverArtData.DataSize = ms.Length;

                TagsLib.TagsLibrary_AddCoverArt(HTags, TTagType.ttAutomatic, CoverArtData);
                ms.Close();
            }
        }
Example #3
0
 public static extern bool TagsLibrary_SetCoverArt(HTAGS Tags, TTagType TagType, int Index, ref TCoverArtData CoverArt);
Example #4
0
 public static extern bool TagsLibrary_SetCoverArtFromFile(HTAGS Tags, TTagType TagType, int Index,  [In, MarshalAs(UnmanagedType.LPWStr)] string FileName, TCoverArtData CoverArt);
Example #5
0
 public static extern int TagsLibrary_AddCoverArt(HTAGS Tags,  TTagType TagType, TCoverArtData CoverArt);