public void SetObjects(object object_0) { this.ipictureElement2_0 = object_0 as IPictureElement2; }
private void AddPictureElement(string strFileName) { IPictureElement2 pictureElement = null; string suffix = strFileName.Substring(strFileName.Length - 3, 3).ToLower(); switch (suffix) { case "jpg": pictureElement = new JpgPictureElementClass(); break; case "gif": pictureElement = new GifPictureElementClass(); break; case "tif": pictureElement = new TifPictureElementClass(); break; case "emf": pictureElement = new EmfPictureElementClass(); break; case "bmp": pictureElement = new BmpPictureElementClass(); break; case "png": pictureElement = new PngPictureElementClass(); break; default: return; } try { pictureElement.ImportPictureFromFile(strFileName); } catch (Exception ex) { XtraMessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } IElement iElement = (IElement)pictureElement; IActiveView iActiveView = this.m_pMapControl.ActiveView; double pictureWidth = 0; double pictureHeight = 0; pictureElement.QueryIntrinsicSize(ref pictureWidth, ref pictureHeight); IEnvelope env = this.m_pMapControl.ActiveView.Extent; tagRECT rect = new tagRECT(); m_pMapControl.ActiveView.ScreenDisplay.DisplayTransformation.TransformRect(env, ref rect, (int)esriDisplayTransformationEnum.esriTransformToDevice); Rectangle rectangle = new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); int x = (rectangle.Left + rectangle.Right) / 2; int y = (rectangle.Top + rectangle.Height) / 2; /* IPoint point = iActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);*/ IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords(point.X, point.Y, point.X + (int)(pictureWidth / 72 * iActiveView.ScreenDisplay.DisplayTransformation.ScaleRatio), point.Y + (int)(pictureHeight / 72 * iActiveView.ScreenDisplay.DisplayTransformation.ScaleRatio)); iElement.Geometry = envelope; IBoundsProperties bp = iElement as IBoundsProperties; bp.FixedAspectRatio = true; pictureElement.MaintainAspectRatio = true; pGraphicsContainer = this.m_pMapControl.ActiveView as IGraphicsContainer; pGraphicsContainer.AddElement(iElement, 0); this.m_pMapControl.ActiveView.Refresh(); }