コード例 #1
0
        /// <summary>
        /// 读取图片并返回Element
        /// </summary>
        /// <param name="sPath"></param>
        /// <returns></returns>
        private IElement GetPicture(string sPath)
        {
            IRasterPicture     pRasterPicture = new RasterPicture();
            IOlePictureElement pOlePicture    = new BmpPictureElement() as IOlePictureElement;

            pOlePicture.ImportPicture(pRasterPicture.LoadPicture(sPath) as stdole.IPictureDisp);
            return(pOlePicture as IElement);
        }
コード例 #2
0
ファイル: CmdNewPicture.cs プロジェクト: secondii/Yutai
        public override void OnClick()
        {
            System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
            openFileDialog.Filter =
                "所有支持格式|*.bmp;*.jpg;*.gif;*.emf;*.tif;*.png|位图文件|*.bmp|JPEG|*.jpg|TIFF|*.tif|EMF|*.emf|PNG|*.png|GIF|*.gif";
            if (openFileDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            string   fileName = openFileDialog.FileName;
            string   text     = System.IO.Path.GetExtension(fileName).ToLower();
            string   text2    = text;
            IElement element;

            if (text2 != null)
            {
                if (text2 == ".bmp")
                {
                    element = new BmpPictureElement();
                }
                else if (text2 == ".jpg")
                {
                    element = new JpgPictureElement();
                }
                else if (text2 == ".gif")
                {
                    element = new GifPictureElement();
                }
                else if (text2 == ".tif")
                {
                    element = new TifPictureElement();
                }
                else if (text2 == ".emf")
                {
                    element = new EmfPictureElement();
                }
                else
                {
                    element = new PngPictureElement();
                }
            }
            else
            {
                element = new PngPictureElement();
            }


            (element as IPictureElement).ImportPictureFromFile(fileName);
            (element as IPictureElement).MaintainAspectRatio = true;
            double num  = 0.0;
            double num2 = 0.0;

            (element as IPictureElement2).QueryIntrinsicSize(ref num, ref num2);
            num  *= 0.0353;
            num2 *= 0.0353;
            IGraphicsContainer arg_11B_0 = this._context.ActiveView as IGraphicsContainer;

            (element as IElementProperties2).AutoTransform = true;
            IEnvelope envelope = new Envelope() as IEnvelope;

            envelope.PutCoords(0.0, 0.0, num, num2);
            element.Geometry = envelope;
            INewElementOperation operation = new NewElementOperation
            {
                ActiveView = this._context.ActiveView,
                Element    = element
            };

            this._context.OperationStack.Do(operation);
        }