本文整理汇总了C#中ISymbol.Draw方法的典型用法代码示例。如果您正苦于以下问题:C# ISymbol.Draw方法的具体用法?C# ISymbol.Draw怎么用?C# ISymbol.Draw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISymbol
的用法示例。
在下文中一共展示了ISymbol.Draw方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawToPictureBox
private void DrawToPictureBox(ISymbol pSym, PictureBox pBox)
{
IGeometry pGeometry = null;
IntPtr hDC;
IEnvelope pEnvelope;
pEnvelope = new EnvelopeClass();
// Reset the PictureBox
pBox.CreateGraphics().Clear(pBox.BackColor);
try
{
if (pSym is IMarkerSymbol)
{
pEnvelope.PutCoords(pBox.Width / 2, pBox.Height / 2, pBox.Width / 2, pBox.Height / 2);
IArea pArea = pEnvelope as IArea;
pGeometry = pArea.Centroid;
}
else if (pSym is ILineSymbol)
{
pEnvelope.PutCoords(0, pBox.Height / 2, pBox.Width, pBox.Height / 2);
IPolyline pPolyline = new PolylineClass();
pPolyline.FromPoint = pEnvelope.LowerLeft;
pPolyline.ToPoint = pEnvelope.UpperRight;
pGeometry = pPolyline;
}
else if (pSym is IFillSymbol)
{
if (pSym is SimpleFillSymbol)
{
pEnvelope.PutCoords(5, 5, pBox.Width - 5, pBox.Height - 5);
pGeometry = pEnvelope;
}
else if (pSym is MultiLayerFillSymbol)
{
IMultiLayerFillSymbol pMultiLayerFillSymbol = pSym as IMultiLayerFillSymbol;
//For mLayers As Integer = 0 To pMultiLayerFillSymbol.LayerCount - 1
if (pMultiLayerFillSymbol.get_Layer(0) is PictureFillSymbol)
{
IPictureFillSymbol pPictureFillSymbol = pMultiLayerFillSymbol.get_Layer(0) as IPictureFillSymbol;
Bitmap m = Bitmap.FromHbitmap(new IntPtr(pPictureFillSymbol.Picture.Handle));
//m.MakeTransparent(System.Drawing.ColorTranslator.FromOle(pPictureFillSymbol.Color.RGB))
pBox.Image = m;
return;
}
else if (pMultiLayerFillSymbol.get_Layer(0) is SimpleFillSymbol)
{
pEnvelope.PutCoords(5, 5, pBox.Width - 5, pBox.Height - 5);
pGeometry = pEnvelope;
}
else if (pMultiLayerFillSymbol.get_Layer(0) is GradientFillSymbol)
{
IGradientFillSymbol pGradientFillSymbol = pMultiLayerFillSymbol.get_Layer(0) as IGradientFillSymbol;
IAlgorithmicColorRamp pRamp = pGradientFillSymbol.ColorRamp as IAlgorithmicColorRamp;
System.Drawing.Rectangle rect = new System.Drawing.Rectangle(new System.Drawing.Point(0, 0), new System.Drawing.Size(pBox.Width, pBox.Height));
LinearGradientBrush lgBrush = new LinearGradientBrush(rect,
System.Drawing.ColorTranslator.FromOle(pRamp.FromColor.RGB),
System.Drawing.ColorTranslator.FromOle(pRamp.ToColor.RGB),
45);
Graphics g = pBox.CreateGraphics();
g.FillRectangle(lgBrush, rect);
rect.Width = rect.Width - 1;
rect.Height = rect.Height - 1;
g.DrawRectangle(new Pen(ColorTranslator.FromOle(pGradientFillSymbol.Outline.Color.RGB),
(float)pGradientFillSymbol.Outline.Width), rect);
}
}
else if (pSym is PictureFillSymbol)
{
IPictureFillSymbol pPictureFillSymbol = pSym as IPictureFillSymbol;
Bitmap m = Bitmap.FromHbitmap(new IntPtr(pPictureFillSymbol.Picture.Handle));
//m.MakeTransparent(System.Drawing.ColorTranslator.FromOle(pPictureFillSymbol.Color.RGB))
pBox.Image = m;
return;
}
}
hDC = GetDC(pBox.Handle);
pSym.SetupDC(hDC.ToInt32(), null);
pSym.ROP2 = esriRasterOpCode.esriROPCopyPen;
if (pGeometry != null)
pSym.Draw(pGeometry);
pSym.ResetDC();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
示例2: DrawToTarget
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();
}
示例3: GetBitmap
private int GetBitmap(ISymbol symbol, IGeometry geometry, int lWidth, int lHeight)
{
if (symbol == null) return 0;
if (geometry == null) return 0;
RECT rect;
rect.Left = 0;
rect.Top = 0;
rect.Right = lWidth;
rect.Bottom = lHeight;
int hDC = GetDC(0);
int hMemDC = CreateCompatibleDC(hDC);
int hBitmap = CreateCompatibleBitmap(hDC, lWidth, lHeight);
int hOldBitmap = SelectObject(hMemDC, hBitmap);
int hBrush = CreateSolidBrush(RGB2Long(255, 255, 255));
int hOldBrush = SelectObject(hMemDC, hBrush);
FillRect(hMemDC, rect, hBrush);//paint a white background.
symbol.SetupDC(hMemDC, null);
symbol.Draw(geometry);
symbol.ResetDC();
SelectObject(hDC, hOldBitmap);
SelectObject(hDC, hOldBrush);
DeleteObject(hBrush);
ReleaseDC(0, hMemDC);
ReleaseDC(0, hDC);
DeleteDC(hMemDC);
DeleteDC(hDC);
return hBitmap;
}
示例4: DrawToPictureBox
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;
}
示例5: DrawToDC
private bool DrawToDC(int hdc, int lWidth, int lHeight, ISymbol pSymbol, int lGap)
{
// Create the Transformation and Geometry required by ISymbol::Draw.
IEnvelope pEnvelope;
ITransformation pTransformation;
IGeometry pGeom;
pEnvelope = new EnvelopeClass();
pEnvelope.PutCoords(lGap, lGap, lWidth - lGap, lHeight - lGap);
pTransformation = CreateTransFromDC(hdc, lWidth, lHeight);
pGeom = CreateSymShape(pSymbol, pEnvelope);
// Perform the Draw operation.
if (pTransformation == null || pGeom == null) return false;
pSymbol.SetupDC(hdc, pTransformation);
pSymbol.Draw(pGeom);
pSymbol.ResetDC();
return true;
}
示例6: DrawToPictureBox
private Bitmap DrawToPictureBox(ISymbol pSym, PictureBox pBox)
{
IGeometry pGeometry = null;
System.Drawing.Graphics pGraphics = null;
pGraphics = System.Drawing.Graphics.FromHwnd(pBox.Handle);
pGraphics.FillRectangle(System.Drawing.Brushes.White, pBox.ClientRectangle);
Bitmap image = new Bitmap(pBox.Width, pBox.Height, pGraphics);
IEnvelope pEnvelope = new EnvelopeClass();
if (pSym is IMarkerSymbol)
{
IPoint 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)
{
pEnvelope.PutCoords(0, pBox.Height / 2, pBox.Width, pBox.Height / 2);
IPolyline pPolyline = new PolylineClass();
pPolyline.FromPoint = pEnvelope.LowerLeft;
pPolyline.ToPoint = pEnvelope.UpperRight;
pGeometry = pPolyline;
}
if (pSym is IFillSymbol)
{
pEnvelope.PutCoords(1, 1, pBox.Width - 1, pBox.Height - 1);
pGeometry = pEnvelope;
if (pSym is IMultiLayerFillSymbol)
{
IMultiLayerFillSymbol pMultiLayerFillSymbol = pSym as IMultiLayerFillSymbol;
//For mLayers As Integer = 0 To pMultiLayerFillSymbol.LayerCount - 1
for (int i = 0; i < pMultiLayerFillSymbol.LayerCount; i++)
{
if (pMultiLayerFillSymbol.get_Layer(i) is IPictureFillSymbol)
{
IPictureFillSymbol pPictureFillSymbol = pMultiLayerFillSymbol.get_Layer(0) as IPictureFillSymbol;
image = Bitmap.FromHbitmap(new IntPtr(pPictureFillSymbol.Picture.Handle));
//m.MakeTransparent(System.Drawing.ColorTranslator.FromOle(pPictureFillSymbol.Color.RGB))
return image;
}
else if (pMultiLayerFillSymbol.get_Layer(i) is ISimpleFillSymbol)
{
pEnvelope.PutCoords(1, 1, pBox.Width - 1, pBox.Height - 1);
pGeometry = pEnvelope;
}
else if (pMultiLayerFillSymbol.get_Layer(i) is IGradientFillSymbol)
{
IGradientFillSymbol pGradientFillSymbol = pMultiLayerFillSymbol.get_Layer(0) as IGradientFillSymbol;
IAlgorithmicColorRamp pRamp = pGradientFillSymbol.ColorRamp as IAlgorithmicColorRamp;
System.Drawing.Rectangle rect = new System.Drawing.Rectangle(new System.Drawing.Point(0, 0), new System.Drawing.Size(pBox.Width, pBox.Height));
LinearGradientBrush lgBrush = new LinearGradientBrush(rect,
System.Drawing.ColorTranslator.FromOle(pRamp.FromColor.RGB),
System.Drawing.ColorTranslator.FromOle(pRamp.ToColor.RGB),
45);
pGraphics.FillRectangle(lgBrush, rect);
rect.Width = rect.Width - 1;
rect.Height = rect.Height - 1;
pGraphics.DrawRectangle(new Pen(ColorTranslator.FromOle(pGradientFillSymbol.Outline.Color.RGB),
(float)pGradientFillSymbol.Outline.Width), rect);
image = new Bitmap(pBox.Width, pBox.Height, pGraphics);
}
}
}
else if (pSym is IPictureFillSymbol)
{
IPictureFillSymbol pPictureFillSymbol = pSym as IPictureFillSymbol;
image = Bitmap.FromHbitmap(new IntPtr(pPictureFillSymbol.Picture.Handle));
//m.MakeTransparent(System.Drawing.ColorTranslator.FromOle(pPictureFillSymbol.Color.RGB))
return image;
}
}
IntPtr hDC = GetDC(pBox.Handle);
pSym.SetupDC(hDC.ToInt32(), null);
pSym.ROP2 = esriRasterOpCode.esriROPCopyPen;
if (pGeometry != null) pSym.Draw(pGeometry);
pSym.ResetDC();
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;
}
示例7: ImageFromSymbol
private Image ImageFromSymbol(ISymbol symbol, Int32 width, Int32 height)
{
if (symbol == null)
return null;
try
{
Bitmap bitmap = new Bitmap(width, height);
Graphics g = Graphics.FromImage(bitmap);
IntPtr hdc = g.GetHdc();
IGeometry geometry = null;
if (symbol is IMarkerSymbol)
{
IPoint point = new PointClass();
point.X = (width / 2);
point.Y = (height / 2);
geometry = point;
}
else if (symbol is ILineSymbol)
{
IPolyline line = new PolylineClass();
IPoint ptFrom = new PointClass();
IPoint ptTo = new PointClass();
ptFrom.X = 3; ptFrom.Y = (height / 2);
ptTo.X = (width - 3); ptTo.Y = ptFrom.Y;
line.FromPoint = ptFrom;
line.ToPoint = ptTo;
geometry = line;
}
else
{
IEnvelope bounds = new EnvelopeClass();
bounds.XMin = 1; bounds.XMax = width - 1;
bounds.YMin = 1; bounds.YMax = height - 1;
geometry = bounds;
}
symbol.SetupDC(hdc.ToInt32(), null);
symbol.Draw(geometry);
symbol.ResetDC();
g.ReleaseHdc(hdc);
g.Dispose();
return bitmap as Image;
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message);
return null;
}
}
示例8: StyleToImage
public static Image StyleToImage(ISymbol sym, int width, int height)
{
if (sym == null)
{
return null;
}
try
{
Image image = new Bitmap(width, height);
Graphics graphics = Graphics.FromImage(image);
IntPtr hdc = graphics.GetHdc();
IEnvelope env = new EnvelopeClass();
env.XMin = 1.0;
env.XMax = width - 1;
env.YMin = 1.0;
env.YMax = height - 1;
IGeometry geometry = CreateGeometryFromSymbol(sym, env);
if (geometry != null)
{
ITransformation transformation = DisplayHelper.CreateTransformationFromHDC(hdc, width, height);
sym.SetupDC((int)hdc, transformation);
sym.Draw(geometry);
sym.ResetDC();
}
graphics.ReleaseHdc(hdc);
return image;
}
catch
{
return null;
}
}