Exemplo n.º 1
0
        public TagPicture(string file, TagPicture.PICTURE_TYPE type, string description)
        {
            UTF8Encoding utf8Encoding = new UTF8Encoding();

            this.Data           = utf8Encoding.GetBytes(file);
            this.MIMEType       = TagPicture.GetMimeTypeFromFile(file);
            this.PictureType    = type;
            this.Description    = description;
            this.PictureStorage = TagPicture.PICTURE_STORAGE.External;
        }
Exemplo n.º 2
0
        public TagPicture(Image image, TagPicture.PICTURE_TYPE pictureType, string description)
        {
            this.PictureType = pictureType;
            this.Description = description;
            ImageConverter imageConverter = new ImageConverter();

            this.Data           = (byte[])imageConverter.ConvertTo(image, typeof(byte[]));
            this.MIMEType       = TagPicture.GetMimeTypeFromImage(image);
            this.PictureStorage = TagPicture.PICTURE_STORAGE.Internal;
        }
Exemplo n.º 3
0
        public TagPicture(TagPicture pic, int size)
        {
            Image pictureImage = pic.PictureImage;
            int   num          = size;
            int   num2         = size;

            if (pictureImage.Width > pictureImage.Height)
            {
                num2 = (int)((double)num2 / ((double)pictureImage.Width / (double)pictureImage.Height));
            }
            else
            {
                num = (int)((double)num / ((double)pictureImage.Height / (double)pictureImage.Width));
            }
            try
            {
                using (Bitmap bitmap = new Bitmap(num, num2))
                {
                    using (Graphics graphics = Graphics.FromImage(bitmap))
                    {
                        graphics.DrawImage(pictureImage, 0, 0, num, num2);
                        using (MemoryStream memoryStream = new MemoryStream())
                        {
                            bitmap.Save(memoryStream, ImageFormat.Jpeg);
                            this.Data = memoryStream.ToArray();
                            memoryStream.Close();
                        }
                    }
                }
            }
            catch
            {
            }
            this.PictureType    = pic.PictureType;
            this.Description    = pic.Description;
            this.MIMEType       = "image/jpeg";
            this.PictureStorage = TagPicture.PICTURE_STORAGE.Internal;
        }
Exemplo n.º 4
0
        internal List <TagPicture> GetAllPictures()
        {
            if (this.HeaderInfo3 == null)
            {
                return(null);
            }
            List <TagPicture> list  = null;
            List <Tag>        list2 = this.WMGetAllAttrib("WM/Picture");

            if (list2 != null && list2.Count > 0)
            {
                list = new List <TagPicture>(list2.Count);
                foreach (Tag pTag in list2)
                {
                    TagPicture picture = this.GetPicture(pTag);
                    if (picture != null)
                    {
                        list.Add(picture);
                    }
                }
            }
            return(list);
        }
Exemplo n.º 5
0
        public TagPicture GetPicture(byte[] frameValue, short frameFlags, int index, bool v2)
        {
            if (frameValue == null)
            {
                return(null);
            }
            TagPicture result = null;

            try
            {
                int num  = 0;
                int num2 = frameValue.Length;
                if ((frameFlags & 1) != 0)
                {
                    this.GetSynchsafeInt32(frameValue[0], frameValue[1], frameValue[2], frameValue[3]);
                    num = 4;
                }
                Encoding frameEncoding = this.GetFrameEncoding(frameValue[num]);
                num++;
                string mimeType;
                if (v2)
                {
                    mimeType = "Unknown";
                    if (frameValue[num] == 74 && frameValue[num + 1] == 80 && frameValue[num + 2] == 71)
                    {
                        mimeType = "image/jpeg";
                    }
                    else if (frameValue[num] == 71 && frameValue[num + 1] == 73 && frameValue[num + 2] == 70)
                    {
                        mimeType = "image/gif";
                    }
                    else if (frameValue[num] == 66 && frameValue[num + 1] == 80 && frameValue[num + 2] == 77)
                    {
                        mimeType = "image/bmp";
                    }
                    else if (frameValue[num] == 80 && frameValue[num + 1] == 78 && frameValue[num + 2] == 71)
                    {
                        mimeType = "image/png";
                    }
                    num += 3;
                }
                else
                {
                    mimeType = this.ReadTextZero(frameValue, ref num);
                    num++;
                }
                byte b = frameValue[num];
                TagPicture.PICTURE_TYPE pictureType;
                try
                {
                    pictureType = (TagPicture.PICTURE_TYPE)b;
                }
                catch
                {
                    pictureType = TagPicture.PICTURE_TYPE.Unknown;
                }
                num++;
                string description = this.ReadTextZero(frameValue, ref num, frameEncoding);
                num++;
                int num3 = frameValue.Length - num;
                if (num3 > 0)
                {
                    byte[] array = new byte[num3];
                    Array.Copy(frameValue, num, array, 0, num3);
                    if ((frameFlags & 2) != 0)
                    {
                        List <byte> list = new List <byte>(num3);
                        for (int i = 0; i < num3; i++)
                        {
                            list.Add(array[i]);
                            if (i < num3 - 1 && array[i] == 255 && array[i + 1] == 0)
                            {
                                i++;
                            }
                        }
                        array = list.ToArray();
                    }
                    result = new TagPicture(index, mimeType, pictureType, description, array);
                }
            }
            catch
            {
            }
            return(result);
        }
Exemplo n.º 6
0
        private TagPicture GetPicture(Tag pTag)
        {
            TagPicture result   = null;
            string     mimeType = "Unknown";

            TagPicture.PICTURE_TYPE pictureType  = TagPicture.PICTURE_TYPE.Unknown;
            MemoryStream            memoryStream = null;
            BinaryReader            binaryReader = null;

            if (pTag.Name == "WM/Picture")
            {
                try
                {
                    memoryStream = new MemoryStream((byte[])pTag);
                    binaryReader = new BinaryReader(memoryStream);
                    if (Utils.Is64Bit)
                    {
                        mimeType = Marshal.PtrToStringUni(new IntPtr(binaryReader.ReadInt64()));
                    }
                    else
                    {
                        mimeType = Marshal.PtrToStringUni(new IntPtr(binaryReader.ReadInt32()));
                    }
                    byte b = binaryReader.ReadByte();
                    try
                    {
                        pictureType = (TagPicture.PICTURE_TYPE)b;
                    }
                    catch
                    {
                        pictureType = TagPicture.PICTURE_TYPE.Unknown;
                    }
                    string description;
                    if (Utils.Is64Bit)
                    {
                        description = Marshal.PtrToStringUni(new IntPtr(binaryReader.ReadInt64()));
                    }
                    else
                    {
                        description = Marshal.PtrToStringUni(new IntPtr(binaryReader.ReadInt32()));
                    }
                    int    num   = binaryReader.ReadInt32();
                    byte[] array = new byte[num];
                    if (Utils.Is64Bit)
                    {
                        Marshal.Copy(new IntPtr(binaryReader.ReadInt64()), array, 0, num);
                    }
                    else
                    {
                        Marshal.Copy(new IntPtr(binaryReader.ReadInt32()), array, 0, num);
                    }
                    result = new TagPicture(pTag.Index, mimeType, pictureType, description, array);
                }
                catch
                {
                }
                finally
                {
                    if (binaryReader != null)
                    {
                        binaryReader.Close();
                    }
                    if (memoryStream != null)
                    {
                        memoryStream.Close();
                        memoryStream.Dispose();
                    }
                }
            }
            return(result);
        }
Exemplo n.º 7
0
 internal TagPicture(byte[] pData, int pType)
 {
     this.PictureStorage = TagPicture.PICTURE_STORAGE.Internal;
     if (pType == 1)
     {
         this.AttributeIndex = -1;
         this.MIMEType       = "Unknown";
         this.PictureType    = TagPicture.PICTURE_TYPE.Unknown;
         this.Description    = "";
         MemoryStream memoryStream = null;
         BinaryReader binaryReader = null;
         if (pData == null || pData.Length <= 32)
         {
             return;
         }
         try
         {
             memoryStream     = new MemoryStream(pData);
             binaryReader     = new BinaryReader(memoryStream);
             this.PictureType = (TagPicture.PICTURE_TYPE)TagPicture.ReadInt32(binaryReader);
             int count = TagPicture.ReadInt32(binaryReader);
             this.MIMEType = Encoding.UTF8.GetString(binaryReader.ReadBytes(count));
             int count2 = TagPicture.ReadInt32(binaryReader);
             this.Description = Encoding.UTF8.GetString(binaryReader.ReadBytes(count2));
             binaryReader.ReadInt32();
             binaryReader.ReadInt32();
             binaryReader.ReadInt32();
             binaryReader.ReadInt32();
             int count3 = TagPicture.ReadInt32(binaryReader);
             this.Data = binaryReader.ReadBytes(count3);
             return;
         }
         catch
         {
             return;
         }
         finally
         {
             try
             {
                 if (binaryReader != null)
                 {
                     binaryReader.Close();
                 }
                 if (memoryStream != null)
                 {
                     memoryStream.Close();
                     memoryStream.Dispose();
                 }
                 if (binaryReader != null)
                 {
                     binaryReader.Dispose();
                 }
             }
             catch
             {
             }
         }
     }
     if (pType == 2)
     {
         this.AttributeIndex = -1;
         this.MIMEType       = "Unknown";
         this.PictureType    = TagPicture.PICTURE_TYPE.Unknown;
         this.Description    = "";
         if (pData == null || pData.Length == 0)
         {
             return;
         }
         try
         {
             int num = 0;
             while (pData[num] != 0)
             {
                 num++;
             }
             this.Description = Encoding.UTF8.GetString(pData, 0, num);
             num++;
             this.Data = new byte[pData.Length - num];
             Array.Copy(pData, num, this.Data, 0, this.Data.Length);
             if (this.PictureImage != null)
             {
                 this.MIMEType = TagPicture.GetMimeTypeFromImage(this.PictureImage);
             }
             return;
         }
         catch
         {
             return;
         }
     }
     this.AttributeIndex = -1;
     this.MIMEType       = "Unknown";
     this.PictureType    = TagPicture.PICTURE_TYPE.FrontAlbumCover;
     this.Description    = "CoverArt";
     this.Data           = pData;
     if (this.PictureImage != null)
     {
         this.MIMEType = TagPicture.GetMimeTypeFromImage(this.PictureImage);
     }
 }