Esempio n. 1
0
        public IBinaryRecord Read()
        {
            if (!this.IsFormatRead)
            {
                this.IsFormatRead = true;
                var format = new WmfFormat();
                format.Read(reader);
                return(format);
            }

            if (!this.IsHeaderRead)
            {
                this.IsHeaderRead = true;
                var header = new WmfHeader();
                header.Read(reader);
                return(header);
            }

            long begin = reader.BaseStream.Position;

            uint   length = reader.ReadUInt32();           //Length in WORDs
            ushort type   = reader.ReadUInt16();

            var rt     = (RecordType)type;
            var record = WmfHelper.GetRecordByType(rt) as WmfBinaryRecord;

            if (record == null)
            {
                record            = new WmfUnknownRecord();
                record.RecordType = rt;                 //Only set for UnknownRecord otherwise it is already defined by attribute above the class
            }

            record.RecordSize = length;
            record.Read(reader);

            long end    = reader.BaseStream.Position;
            long rlen   = end - begin;           //Read length
            long excess = 2 * length - rlen;

            if (excess > 0)
            {
                //Oops, reader did not read whole record?!
                reader.Skip((int)excess);
            }

            return(record);
        }
            //ExEnd:SourceWmfFilePath

            /// <summary>
            /// Reads metadata from wmf file
            /// </summary> 
            public static void GetMetadataProperties()
            {
                try
                {
                    //ExStart:GetMetadatPropertiesInWMF

                    // initialize WmfFormat class
                    WmfFormat wmfFormat = new WmfFormat(Common.MapSourceFilePath(wmfFilePath));

                    // get width
                    int width = wmfFormat.Width;

                    // get height
                    int height = wmfFormat.Height;
                    //display height and width in console
                    Console.Write("Width: {0}, Height: {1}", width, height);
                    //ExEnd:GetMetadatPropertiesInWMF
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }