本文整理汇总了C#中ShapeCollection.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# ShapeCollection.Clear方法的具体用法?C# ShapeCollection.Clear怎么用?C# ShapeCollection.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShapeCollection
的用法示例。
在下文中一共展示了ShapeCollection.Clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Merge
/// <summary>
/// Modifies the first Polygon so that it is the result of both merged polygons.
/// This method assumes that the polygons collide and that both are drawn
/// clockwise.
/// </summary>
/// <param name="polygon">The first polygon. This one will be modified.</param>
/// <param name="otherPolygon">The second polygon which will not be modified.</param>
#endregion
public static void Merge(Polygon polygon, Polygon otherPolygon)
{
// Vic says: This is useful for debugging merging. Don't remove it!!!
bool shouldDebug = false;
Segment[] firstSegments;
Segment[] secondSegments;
List<ContactPoint> contactPoints = GetContactPoints(polygon, otherPolygon, out firstSegments, out secondSegments);
#if !SILVERLIGHT && !WINDOWS_PHONE && !XBOX360 && !IOS && !MONODROID
if (shouldDebug)
{
ShapeCollection sc = new ShapeCollection();
sc.Polygons.Add(polygon);
sc.Polygons.Add(otherPolygon);
for (int i = 0; i < contactPoints.Count; i++)
{
Circle circle = new Circle();
circle.Radius = .5f;
circle.Position = contactPoints[i].Position;
if (contactPoints[i].ContactType == ContactType.SegmentIntersection)
{
circle.Color = Color.Orange;
}
else
{
circle.Color = Color.Green;
}
sc.Circles.Add(circle);
}
FlatRedBall.Content.Math.Geometry.ShapeCollectionSave scs =
new FlatRedBall.Content.Math.Geometry.ShapeCollectionSave();
scs.AddPolygonList(sc.Polygons);
scs.AddCircleList(sc.Circles);
string fileName =
FlatRedBall.IO.FileManager.MyDocuments + "mergeTest.shcx";
scs.Save(fileName);
sc.Clear();
}
#endif
int firstPointToStartAt = GetPointToStartAt(polygon, otherPolygon);
if (firstPointToStartAt == -1)
{
throw new NotImplementedException();
// return a polygon that is the same shape as the rectangle
}
List<Vector3> thisVertices = GetAbsoluteVertices(firstSegments);
List<Vector3> otherVertices = GetAbsoluteVertices(secondSegments);
SetPointsFromContactPointsAndVertices(polygon, otherPolygon, contactPoints, firstPointToStartAt, thisVertices, otherVertices);
}
示例2: CreateImage
//.........这里部分代码省略.........
switch (imageFormat) {
case ImageFileFormat.Svg:
throw new NotImplementedException();
case ImageFileFormat.Emf:
case ImageFileFormat.EmfPlus:
// Create MetaFile and graphics context
IntPtr hdc = infoGraphics.GetHdc();
try {
Rectangle bounds = Rectangle.Empty;
bounds.Size = imageBounds.Size;
result = new Metafile(hdc, bounds, MetafileFrameUnit.Pixel,
(imageFormat == ImageFileFormat.Emf) ? EmfType.EmfOnly : EmfType.EmfPlusDual,
Name);
} finally {
infoGraphics.ReleaseHdc(hdc);
}
break;
case ImageFileFormat.Bmp:
case ImageFileFormat.Gif:
case ImageFileFormat.Jpeg:
case ImageFileFormat.Png:
case ImageFileFormat.Tiff:
int imgWidth = imageBounds.Width;
int imgHeight = imageBounds.Height;
if (dpi > 0 && dpi != infoGraphics.DpiX || dpi != infoGraphics.DpiY) {
scaleX = dpi / infoGraphics.DpiX;
scaleY = dpi / infoGraphics.DpiY;
imgWidth = (int)Math.Round(scaleX * imageBounds.Width);
imgHeight = (int)Math.Round(scaleY * imageBounds.Height);
}
result = new Bitmap(Math.Max(1, imgWidth), Math.Max(1, imgHeight));
((Bitmap)result).SetResolution(dpi, dpi);
break;
default:
throw new NShapeUnsupportedValueException(typeof(ImageFileFormat), imageFormat);
}
// Draw diagram
using (Graphics gfx = Graphics.FromImage(result)) {
GdiHelpers.ApplyGraphicsSettings(gfx, RenderingQuality.MaximumQuality);
// Fill background with background color
if (backgroundColor.A < 255) {
if (imageFormat == ImageFileFormat.Bmp || imageFormat == ImageFileFormat.Jpeg) {
// For image formats that do not support transparency, fill background with the RGB part of
// the given backgropund color
gfx.Clear(Color.FromArgb(255, backgroundColor));
} else if (backgroundColor.A > 0) {
// Skip filling background for meta files if transparency is 100%:
// Filling Background with Color.Transparent causes graphical glitches with many applications
gfx.Clear(backgroundColor);
}
} else {
// Graphics.Clear() does not work as expected for classic EMF (fills only the top left pixel
// instead of the whole graphics context).
if (imageFormat == ImageFileFormat.Emf) {
using (SolidBrush brush = new SolidBrush(backgroundColor))
gfx.FillRectangle(brush, gfx.ClipBounds);
} else gfx.Clear(backgroundColor);
}
// Transform graphics (if necessary)
gfx.TranslateTransform(-imageBounds.X, -imageBounds.Y, MatrixOrder.Prepend);
if (scaleX != 1 || scaleY != 1) gfx.ScaleTransform(scaleX, scaleY, MatrixOrder.Append);
// Draw diagram background
if (withBackground) DrawBackground(gfx, imageBounds);
// Draw diagram shapes
if (shapes == null) {
foreach (Shape shape in diagramShapes.BottomUp) shape.Draw(gfx);
} else {
// Add shapes to ShapeCollection (in order to maintain zOrder while drawing)
int cnt = (shapes is ICollection) ? ((ICollection)shapes).Count : -1;
ShapeCollection shapeCollection = new ShapeCollection(cnt);
foreach (Shape s in shapes) {
// Sort out duplicate references to shapes (as they can occur in the result of Diagram.FindShapes())
if (shapeCollection.Contains(s)) continue;
shapeCollection.Add(s, s.ZOrder);
}
// Draw shapes
foreach (Shape shape in shapeCollection.BottomUp)
shape.Draw(gfx);
shapeCollection.Clear();
}
// Reset transformation
gfx.ResetTransform();
}
// Restore original graphics settings
HighQualityRendering = originalQualitySetting;
UpdateBrushes();
return result;
} finally {
if (disposeInfoGfx)
GdiHelpers.DisposeObject(ref infoGraphics);
}
}