Beispiel #1
0
        public void ValidationOKTest()
        {
            /*
             *  T___
             *  TXXX
             *  WXXX
             *  APIC
             */

            var tagContainer = new TagContainerV3();
            tagContainer.Tag.SetExtendedHeader(0, false);
            tagContainer.Tag.SetHeaderOptions(false, false, false);

            var textFrame = new TextFrame("TALB", "My Albun", Encoding.Default);
            var userDefineTextFrame = new UserDefinedTextFrame("my comment", "so", Encoding.Default);
            var linkFrame = new UserDefinedUrlLinkFrame("Id3Tag", "Id3Tag.codeplex.com", Encoding.Default);
            var pictureFrame = new PictureFrame(
                Encoding.Default,
                "image/jpeg",
                "la",
                PictureType.Other,
                new byte[] {0x11, 0x12, 0x13, 0x14});

            tagContainer.Add(textFrame);
            tagContainer.Add(userDefineTextFrame);
            tagContainer.Add(linkFrame);
            tagContainer.Add(pictureFrame);

            WriteTagContainer(tagContainer);

            // OK... passed!
        }
        public void ConstructorTest()
        {
            Encoding encoding = Encoding.Default;
            const string mime = "ABCD";
            const string description = "EFGH";
            const PictureType pictureType = PictureType.Other;
            var pictureData = new byte[] {0x20, 0x21, 0x22, 0x23};

            var frame = new PictureFrame(encoding, mime, description, pictureType, pictureData);

            Assert.AreEqual(frame.TextEncoding.CodePage, encoding.CodePage);
            Assert.AreEqual(frame.MimeType, mime);
            Assert.AreEqual(frame.Description, description);
            Assert.AreEqual(frame.PictureCoding, pictureType);
            Assert.IsTrue(ComparePayload(frame.PictureData, pictureData));
        }
        public void ConvertISO8859()
        {
            Encoding encoding = Encoding.Default;
            const string mimeType = "ABCD";
            const PictureType pictureType = PictureType.CoverFront;
            const string description = "EFGH";
            var data = new byte[] {0x20, 0x21, 0x22, 0x23};

            var pictureFrame = new PictureFrame(encoding, mimeType, description, pictureType, data);
            RawFrame rawFrame = pictureFrame.Convert(TagVersion.Id3V23);

            var refBytes = new byte[]
                               {
                                   0x00, 0x41, 0x42, 0x43, 0x44, 0x00, 0x03, 0x45, 0x46, 0x47, 0x48, 0x00,
                                   0x20, 0x21, 0x22, 0x23
                               };

            Assert.IsTrue(ComparePayload(rawFrame.Payload, refBytes));
        }
        private static void WritePictureFrame(ID3V2TagData data, ICollection<IFrame> container)
        {
            using (FileStream stream = File.Open(data.PictureFile, FileMode.Open))
            {
                //
                //  Read the picture.
                //
                int byteCount = Convert.ToInt32(stream.Length);
                var pictureData = new byte[byteCount];
                stream.Read(pictureData, 0, byteCount);

                //
                //  Add the picture frame.
                //  
                var pictureFrame = new PictureFrame(
                    Encoding.Default,
                    "image/jpg",
                    "Other",
                    PictureType.Other,
                    pictureData);

                container.Add(pictureFrame);
            }
        }
Beispiel #5
0
        private void ShowPicture(PictureFrame pictureFrame)
        {
            labelMimeType.Content = pictureFrame.MimeType;
            labelTextEncoding.Content = pictureFrame.TextEncoding;
            labelDescription.Content = pictureFrame.Description;
            labelPictureType.Content = pictureFrame.PictureCoding;

            ReadOnlyCollection<byte> data = pictureFrame.PictureData;
            try
            {
                var buffer = new byte[data.Count];
                data.CopyTo(buffer, 0);
                Stream pictureStream = new MemoryStream(buffer);

                var bitmap = new BitmapImage();
                bitmap.BeginInit();
                bitmap.StreamSource = pictureStream;
                bitmap.EndInit();

                imagePicture.Source = bitmap;
            }
            catch (Exception ex)
            {
                throw new Id3TagException("Cannot read the picture frame : " + ex.Message);
            }
        }