Exemplo n.º 1
0
 public Image GetThumbnail(string name)
 {
     int num;
     Image image2;
     if (this.CatalogMap == null)
     {
         throw new ObjectDisposedException("ThumbsDb");
     }
     if (!this.CatalogMap.TryGetValue(name, out num))
     {
         return null;
     }
     CompoundStreamEntry entry = this.Thumbs.Root[GetReversedItemId(num)] as CompoundStreamEntry;
     if (entry == null)
     {
         return null;
     }
     using (Stream stream = entry.OpenRead())
     {
         stream.Seek(12L, SeekOrigin.Begin);
         using (Stream stream2 = new SubStream(stream))
         {
             using (Image image = Image.FromStream(stream2))
             {
                 image2 = new Bitmap(image);
             }
         }
     }
     return image2;
 }
Exemplo n.º 2
0
        private object ReadProperty(BinaryReader reader)
        {
            switch (((VarEnum) reader.ReadInt32()))
            {
                case VarEnum.VT_CF:
                {
                    int num3 = reader.ReadInt32();
                    if ((reader.ReadInt32() == -1) && (reader.ReadInt32() == 3))
                    {
                        reader.BaseStream.Seek(8L, SeekOrigin.Current);
                        using (Stream stream = new SubStream(reader.BaseStream, FileAccess.Read, (long) (num3 - 0x10)))
                        {
                            return new Metafile(stream);
                        }
                    }
                    return null;
                }
                case VarEnum.VT_CLSID:
                    return new Guid(reader.ReadBytes(0x10));

                case VarEnum.VT_FILETIME:
                    return DateTime.FromFileTime(reader.ReadInt64());

                case VarEnum.VT_EMPTY:
                    return null;

                case VarEnum.VT_NULL:
                    return DBNull.Value;

                case VarEnum.VT_I2:
                    return reader.ReadInt16();

                case VarEnum.VT_I4:
                    return reader.ReadInt32();

                case VarEnum.VT_R4:
                    return reader.ReadSingle();

                case VarEnum.VT_R8:
                    return reader.ReadDouble();

                case VarEnum.VT_BSTR:
                    return Encoding.Unicode.GetString(reader.ReadBytes(reader.ReadInt32()));

                case VarEnum.VT_BOOL:
                    return Convert.ToBoolean(reader.ReadInt16());

                case VarEnum.VT_UI1:
                    return reader.ReadByte();

                case VarEnum.VT_UI2:
                    return reader.ReadUInt16();

                case VarEnum.VT_UI4:
                    return reader.ReadUInt32();

                case VarEnum.VT_I8:
                    return reader.ReadInt64();

                case VarEnum.VT_UI8:
                    return reader.ReadUInt64();

                case VarEnum.VT_LPSTR:
                {
                    byte[] array = reader.ReadBytes(reader.ReadInt32());
                    int index = Array.IndexOf<byte>(array, 0);
                    if (this.DefaultEncoding == null)
                    {
                        this.DefaultEncoding = Encoding.Default;
                    }
                    return this.DefaultEncoding.GetString(array, 0, (index < 0) ? array.Length : index);
                }
                case VarEnum.VT_LPWSTR:
                {
                    byte[] sequense = reader.ReadBytes(reader.ReadInt32());
                    byte[] buffer3 = new byte[2];
                    int num2 = ByteArrayHelper.IndexOf(sequense, buffer3, sequense.Length);
                    return Encoding.Unicode.GetString(sequense, 0, (num2 < 0) ? sequense.Length : num2);
                }
            }
            throw new InvalidDataException("Unsupported variant type");
        }
 private Image ReadThumbnail()
 {
     try
     {
         using (Stream stream = this._FileInfo.OpenRead())
         {
             stream.Position = this.ThumbnailStreamStart;
             using (Stream stream2 = new SubStream(stream, (long) this.ThumbnailStreamSize))
             {
                 using (Image image = Image.FromStream(stream2))
                 {
                     return new Bitmap(image);
                 }
             }
         }
     }
     catch (Exception exception)
     {
         PropertyProviderManager.ProviderTrace.TraceException(TraceEventType.Error, exception);
         this.HasCapability &= ~PsdCapability.Thumbnail;
         this._FileInfo = null;
         base.ResetAvailableSet();
     }
     return null;
 }