private Bitmap DrawToPictureBox(ISymbol pSym, PictureBox pBox) { IPoint pPoint = null; IGeometry pGeometry = null; int hDC; System.Drawing.Graphics pGraphics = null; pGraphics = System.Drawing.Graphics.FromHwnd(pBox.Handle); //clear drawing canvas pGraphics.FillRectangle(System.Drawing.Brushes.White, pBox.ClientRectangle); if (pSym is IMarkerSymbol) { pPoint = new PointClass(); //the geometry of a MarkerSymbol pPoint.PutCoords(pBox.Width / 2, pBox.Height / 2); //center in middle of pBox pGeometry = pPoint; } if (pSym is ILineSymbol) { ISegmentCollection polyline = new ESRI.ArcGIS.Geometry.PolylineClass(); ISegment line = new ESRI.ArcGIS.Geometry.LineClass(); IPoint fromPoint = new PointClass(); fromPoint.PutCoords(pBox.Left, pBox.Bottom); IPoint toPoint = new PointClass(); toPoint.PutCoords(pBox.Right, pBox.Top); line.FromPoint = fromPoint; line.ToPoint = toPoint; object missing = Type.Missing; polyline.AddSegment(line, ref missing, ref missing); pGeometry = polyline as IGeometry; } if (pSym is IFillSymbol) { IEnvelope pEnvelope = new EnvelopeClass(); pEnvelope.PutCoords(pBox.Left, pBox.Top, pBox.Right, pBox.Bottom); pGeometry = pEnvelope; } hDC = GetDC(pBox.Handle.ToInt32()); pSym.SetupDC(hDC, null); pSym.ROP2 = esriRasterOpCode.esriROPCopyPen; pSym.Draw(pGeometry); pSym.ResetDC(); Bitmap image = new Bitmap(pBox.Width, pBox.Height, pGraphics); Graphics g2 = Graphics.FromImage(image); //获得屏幕的句柄 IntPtr dc3 = pGraphics.GetHdc(); //获得位图的句柄 IntPtr dc2 = g2.GetHdc(); BitBlt(dc2, 0, 0, pBox.Width, pBox.Height, dc3, 0, 0, SRCCOPY); pGraphics.ReleaseHdc(dc3); //释放屏幕句柄 g2.ReleaseHdc(dc2); //释放位图句柄 //image.Save("c:\\MyJpeg.Icon", ImageFormat.Bmp); return(image); }
private void DrawToTarget(ISymbol pSym, PictureBox pBox) { IPoint pPoint = null; IGeometry pGeometry = null; IDisplayTransformation pDisplayTrans = null; if (pSym is IMarkerSymbol) { pPoint = new PointClass(); //the geometry of a MarkerSymbol pPoint.PutCoords(pBox.Width / 2, pBox.Height / 2); //center in middle of pBox pGeometry = pPoint; } if (pSym is ILineSymbol) { ISegmentCollection polyline = new ESRI.ArcGIS.Geometry.PolylineClass(); ISegment line = new ESRI.ArcGIS.Geometry.LineClass(); IPoint fromPoint = new PointClass(); fromPoint.PutCoords(pBox.Left, pBox.Bottom); IPoint toPoint = new PointClass(); toPoint.PutCoords(pBox.Right, pBox.Top); line.FromPoint = fromPoint; line.ToPoint = toPoint; object missing = Type.Missing; polyline.AddSegment(line, ref missing, ref missing); pGeometry = polyline as IGeometry; } if (pSym is IFillSymbol) { IEnvelope pEnvelope = new EnvelopeClass(); pEnvelope.PutCoords(pBox.Left, pBox.Top, pBox.Right, pBox.Bottom); pGeometry = pEnvelope; } pDisplayTrans = getTransformation(pBox) as IDisplayTransformation; pSym.SetupDC(pBox.Handle.ToInt32(), null); pSym.ROP2 = esriRasterOpCode.esriROPCopyPen; pSym.Draw(pGeometry); pSym.ResetDC(); }
private bool UpdatePointXYFromGeometry(ITable PointTable, IQueryFilter QueryFilter, bool Unversioned, double UpdateIfMoreThanTolerance, out int ChangedPointCount) { IProgressDialogFactory pProgressorDialogFact = new ProgressDialogFactoryClass(); ITrackCancel pTrackCancel = new CancelTrackerClass(); IStepProgressor pStepProgressor = pProgressorDialogFact.Create(pTrackCancel, ArcMap.Application.hWnd); IProgressDialog2 pProgressorDialog = (IProgressDialog2)pStepProgressor; try { pStepProgressor.MinRange = 0; pStepProgressor.MaxRange = PointTable.RowCount(null); pStepProgressor.StepValue = 1; pProgressorDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressSpiral; bool bCont = true; IRow pPointFeat = null; ICursor pPtCurs = null; ChangedPointCount = 0; if (Unversioned) { ITableWrite pTableWr = (ITableWrite)PointTable;//used for unversioned table pPtCurs = pTableWr.UpdateRows(QueryFilter, false); } else pPtCurs = PointTable.Update(QueryFilter, false); pPointFeat = pPtCurs.NextRow(); int iPointIdx_X = pPtCurs.Fields.FindField("X"); int iPointIdx_Y = pPtCurs.Fields.FindField("Y"); pProgressorDialog.ShowDialog(); pStepProgressor.Message = "Updating point data..."; while (pPointFeat != null) {//loop through all of the fabric points, and if any of the point id values are in the deleted set, //then remove the control name from the point's NAME field bCont = pTrackCancel.Continue(); if (!bCont) break; IFeature pFeat = (IFeature)pPointFeat; IPoint pPtSource = (IPoint)pFeat.ShapeCopy; if (pPtSource == null) { Marshal.ReleaseComObject(pPointFeat); //garbage collection pPointFeat = pPtCurs.NextRow(); continue; } if (pPtSource.IsEmpty) { Marshal.ReleaseComObject(pPointFeat); //garbage collection pPointFeat = pPtCurs.NextRow(); continue; } IPoint pPtTarget = new ESRI.ArcGIS.Geometry.PointClass(); pPtTarget.X = Convert.ToDouble(pPointFeat.get_Value(iPointIdx_X)); pPtTarget.Y = Convert.ToDouble(pPointFeat.get_Value(iPointIdx_Y)); ILine pLine = new ESRI.ArcGIS.Geometry.LineClass(); pLine.PutCoords(pPtSource, pPtTarget); if (pLine.Length > UpdateIfMoreThanTolerance) { pPointFeat.set_Value(iPointIdx_X, pPtSource.X); pPointFeat.set_Value(iPointIdx_Y, pPtSource.Y); //if (Unversioned) pPtCurs.UpdateRow(pPointFeat); //else // pPointFeat.Store(); ChangedPointCount++; string sCnt = ChangedPointCount.ToString() + " of " + pStepProgressor.MaxRange.ToString(); pStepProgressor.Message = "Updating point data..." + sCnt; } Marshal.ReleaseComObject(pPointFeat); //garbage collection pPointFeat = pPtCurs.NextRow(); if (pStepProgressor.Position < pStepProgressor.MaxRange) pStepProgressor.Step(); } Marshal.ReleaseComObject(pPtCurs); //garbage collection return bCont; } catch (COMException ex) { MessageBox.Show("Problem updating point XY from shape: " + Convert.ToString(ex.ErrorCode)); ChangedPointCount = 0; return false; } finally { pStepProgressor = null; if (!(pProgressorDialog == null)) pProgressorDialog.HideDialog(); pProgressorDialog = null; } }
private bool UpdatePointXYFromGeometry(ITable PointTable, IQueryFilter QueryFilter, bool Unversioned, double UpdateIfMoreThanTolerance, out int ChangedPointCount) { IApplication pApp = (IApplication)ArcMap.Application; if (pApp == null) { //if the app is null then must be running from ArcCatalog...based on equivalent test in calling function. pApp = (IApplication)ArcCatalog.Application; } IProgressDialogFactory pProgressorDialogFact = new ProgressDialogFactoryClass(); ITrackCancel pTrackCancel = new CancelTrackerClass(); IStepProgressor pStepProgressor = pProgressorDialogFact.Create(pTrackCancel, pApp.hWnd); IProgressDialog2 pProgressorDialog = (IProgressDialog2)pStepProgressor; try { pStepProgressor.MinRange = 0; pStepProgressor.MaxRange = PointTable.RowCount(null); pStepProgressor.StepValue = 1; pProgressorDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressSpiral; bool bCont = true; IRow pPointFeat = null; ICursor pPtCurs = null; ChangedPointCount = 0; if (Unversioned) { ITableWrite pTableWr = (ITableWrite)PointTable;//used for unversioned table pPtCurs = pTableWr.UpdateRows(QueryFilter, false); } else { pPtCurs = PointTable.Update(QueryFilter, false); } pPointFeat = pPtCurs.NextRow(); int iPointIdx_X = pPtCurs.Fields.FindField("X"); int iPointIdx_Y = pPtCurs.Fields.FindField("Y"); pProgressorDialog.ShowDialog(); pStepProgressor.Message = "Updating point data..."; while (pPointFeat != null) {//loop through all of the fabric points, and if any of the point id values are in the deleted set, //then remove the control name from the point's NAME field bCont = pTrackCancel.Continue(); if (!bCont) { break; } IFeature pFeat = (IFeature)pPointFeat; IPoint pPtSource = (IPoint)pFeat.ShapeCopy; if (pPtSource == null) { Marshal.ReleaseComObject(pPointFeat); //garbage collection pPointFeat = pPtCurs.NextRow(); continue; } if (pPtSource.IsEmpty) { Marshal.ReleaseComObject(pPointFeat); //garbage collection pPointFeat = pPtCurs.NextRow(); continue; } IPoint pPtTarget = new ESRI.ArcGIS.Geometry.PointClass(); pPtTarget.X = Convert.ToDouble(pPointFeat.get_Value(iPointIdx_X)); pPtTarget.Y = Convert.ToDouble(pPointFeat.get_Value(iPointIdx_Y)); ILine pLine = new ESRI.ArcGIS.Geometry.LineClass(); pLine.PutCoords(pPtSource, pPtTarget); if (pLine.Length > UpdateIfMoreThanTolerance) { pPointFeat.set_Value(iPointIdx_X, pPtSource.X); pPointFeat.set_Value(iPointIdx_Y, pPtSource.Y); //if (Unversioned) pPtCurs.UpdateRow(pPointFeat); //else // pPointFeat.Store(); ChangedPointCount++; string sCnt = ChangedPointCount.ToString() + " of " + pStepProgressor.MaxRange.ToString(); pStepProgressor.Message = "Updating point data..." + sCnt; } Marshal.ReleaseComObject(pPointFeat); //garbage collection pPointFeat = pPtCurs.NextRow(); if (pStepProgressor.Position < pStepProgressor.MaxRange) { pStepProgressor.Step(); } } Marshal.ReleaseComObject(pPtCurs); //garbage collection return(bCont); } catch (COMException ex) { MessageBox.Show("Problem updating point XY from shape: " + Convert.ToString(ex.ErrorCode)); ChangedPointCount = 0; return(false); } finally { pStepProgressor = null; if (!(pProgressorDialog == null)) { pProgressorDialog.HideDialog(); } pProgressorDialog = null; } }
private Bitmap DrawToPictureBox(ISymbol pSym, PictureBox pBox) { IPoint pPoint = null; IGeometry pGeometry = null; int hDC; System.Drawing.Graphics pGraphics = null; pGraphics = System.Drawing.Graphics.FromHwnd(pBox.Handle); //clear drawing canvas pGraphics.FillRectangle(System.Drawing.Brushes.White, pBox.ClientRectangle); if (pSym is IMarkerSymbol) { pPoint = new PointClass(); //the geometry of a MarkerSymbol pPoint.PutCoords(pBox.Width / 2, pBox.Height / 2); //center in middle of pBox pGeometry = pPoint; } if (pSym is ILineSymbol) { ISegmentCollection polyline = new ESRI.ArcGIS.Geometry.PolylineClass(); ISegment line = new ESRI.ArcGIS.Geometry.LineClass(); IPoint fromPoint = new PointClass(); fromPoint.PutCoords(pBox.Left, pBox.Bottom); IPoint toPoint = new PointClass(); toPoint.PutCoords(pBox.Right, pBox.Top); line.FromPoint = fromPoint; line.ToPoint = toPoint; object missing = Type.Missing; polyline.AddSegment(line, ref missing, ref missing); pGeometry = polyline as IGeometry; } if (pSym is IFillSymbol) { IEnvelope pEnvelope = new EnvelopeClass(); pEnvelope.PutCoords(pBox.Left, pBox.Top, pBox.Right, pBox.Bottom); pGeometry = pEnvelope; } hDC = GetDC(pBox.Handle.ToInt32()); pSym.SetupDC(hDC, null); pSym.ROP2 = esriRasterOpCode.esriROPCopyPen; pSym.Draw(pGeometry); pSym.ResetDC(); Bitmap image = new Bitmap(pBox.Width, pBox.Height, pGraphics); Graphics g2 = Graphics.FromImage(image); //获得屏幕的句柄 IntPtr dc3 = pGraphics.GetHdc(); //获得位图的句柄 IntPtr dc2 = g2.GetHdc(); BitBlt(dc2, 0, 0, pBox.Width, pBox.Height, dc3, 0, 0, SRCCOPY); pGraphics.ReleaseHdc(dc3);//释放屏幕句柄 g2.ReleaseHdc(dc2);//释放位图句柄 //image.Save("c:\\MyJpeg.Icon", ImageFormat.Bmp); return image; }