Пример #1
0
        /// <summary>
        /// Obtain graphic extent
        /// </summary>
        /// <param name="astream">Stream containing a bitmap or a Jpeg image</param>
        /// <param name="extent">Initial bounding box</param>
        /// <param name="dpi">Resolution in Dots per inch of the image</param>
        /// <returns>Size in twips of the image</returns>
        override public Point GraphicExtent(MemoryStream astream, Point extent,
                                            int dpi)
        {
            int    imagesize;
            int    bitmapwidth, bitmapheight;
            bool   indexed;
            int    numcolors, bitsperpixel;
            string palette;

            bitmapwidth  = 0;
            bitmapheight = 0;
            astream.Seek(0, System.IO.SeekOrigin.Begin);
            if (!GraphicUtils.GetJPegInfo(astream, out bitmapwidth, out bitmapheight))
            {
                bool isgif = false;
                astream.Seek(0, System.IO.SeekOrigin.Begin);
                GraphicUtils.GetBitmapInfo(astream, out bitmapwidth, out bitmapheight, out imagesize, null,
                                           out indexed, out bitsperpixel, out numcolors, out palette, out isgif);
                astream.Seek(0, System.IO.SeekOrigin.Begin);
            }
            if (dpi <= 0)
            {
                return(new Point(extent.X, extent.Y));
            }
            extent.X = (int)Math.Round((double)bitmapwidth / dpi * Twips.TWIPS_PER_INCH);
            extent.Y = (int)Math.Round((double)bitmapheight / dpi * Twips.TWIPS_PER_INCH);
            return(new Point(extent.X, extent.Y));
        }