本文整理匯總了C#中System.Drawing.Region.GetBounds方法的典型用法代碼示例。如果您正苦於以下問題:C# Region.GetBounds方法的具體用法?C# Region.GetBounds怎麽用?C# Region.GetBounds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Drawing.Region
的用法示例。
在下文中一共展示了Region.GetBounds方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: DrawShapeOnGraphics
public override void DrawShapeOnGraphics(GraphicsPath shapeAsGraphicsPath, Graphics g)
{
styleToDecorate.DrawShapeOnGraphics(shapeAsGraphicsPath, g);
Region shapeAsRegion = new Region(shapeAsGraphicsPath);
RectangleF rr = shapeAsRegion.GetBounds(g);
CreateGradient(rr);
g.FillRegion(styleToDecorate.fillBrush_, shapeAsRegion);
}
示例2: AddObject
public void AddObject(Region path, string layer, ToolTipInfo toolTipInfo, System.Drawing.Graphics g)
{
lock (m_QuadTree)
{
RectangleF rf = path.GetBounds(g);
Envelope env = new Envelope(rf.Left, rf.Right, rf.Bottom, rf.Top);
m_QuadTree.Insert(env, new QuickInfoObject(path, layer, toolTipInfo, env));
}
}
示例3: CheckEmpty
// a region with an "empty ctor" graphic path is "empty" (i.e. not infinite)
private void CheckEmpty (string prefix, Region region)
{
Assert.IsTrue (region.IsEmpty (graphic), prefix + "IsEmpty");
Assert.IsFalse (region.IsInfinite (graphic), prefix + "graphic");
RectangleF rect = region.GetBounds (graphic);
Assert.AreEqual (0f, rect.X, prefix + "GetBounds.X");
Assert.AreEqual (0f, rect.Y, prefix + "GetBounds.Y");
Assert.AreEqual (0f, rect.Width, prefix + "GetBounds.Width");
Assert.AreEqual (0f, rect.Height, prefix + "GetBounds.Height");
}
示例4: TestBounds
public void TestBounds()
{
Bitmap bmp = new Bitmap (600, 800);
Graphics dc = Graphics.FromImage (bmp);
Rectangle rect1, rect2;
Region rgn1, rgn2;
RectangleF bounds;
rect1 = new Rectangle (500, 30, 60, 80);
rect2 = new Rectangle (520, 40, 60, 80);
rgn1 = new Region(rect1);
rgn2 = new Region(rect2);
rgn1.Union(rgn2);
bounds = rgn1.GetBounds (dc);
Assert.AreEqual (500, bounds.X);
Assert.AreEqual (30, bounds.Y);
Assert.AreEqual (80, bounds.Width);
Assert.AreEqual (90, bounds.Height);
}
示例5: SetSaveReset
public void SetSaveReset ()
{
Bitmap bmp = new Bitmap (200, 200);
Graphics g = Graphics.FromImage (bmp);
GraphicsState state_default, state_modified;
state_default = g.Save (); // Default
g.CompositingMode = CompositingMode.SourceCopy;
g.CompositingQuality = CompositingQuality.GammaCorrected;
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
g.PageScale = 2;
g.PageUnit = GraphicsUnit.Inch;
g.PixelOffsetMode = PixelOffsetMode.Half;
g.Clip = new Region (new Rectangle (0, 0, 100, 100));
g.RenderingOrigin = new Point (10, 20);
g.SmoothingMode = SmoothingMode.AntiAlias;
g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
state_modified = g.Save (); // Modified
g.CompositingMode = CompositingMode.SourceOver;
g.CompositingQuality = CompositingQuality.Default;
g.InterpolationMode = InterpolationMode.Bilinear;
g.PageScale = 5;
g.PageUnit = GraphicsUnit.Display;
g.PixelOffsetMode = PixelOffsetMode.Default;
g.Clip = new Region (new Rectangle (1, 2, 20, 25));
g.RenderingOrigin = new Point (5, 6);
g.SmoothingMode = SmoothingMode.None;
g.TextRenderingHint = TextRenderingHint.SystemDefault;
g.Restore (state_modified);
Assert.AreEqual (CompositingMode.SourceCopy, g.CompositingMode, "SetSaveReset1");
Assert.AreEqual (CompositingQuality.GammaCorrected, g.CompositingQuality, "SetSaveReset2");
Assert.AreEqual (InterpolationMode.HighQualityBilinear, g.InterpolationMode, "SetSaveReset3");
Assert.AreEqual (2, g.PageScale, "SetSaveReset4");
Assert.AreEqual (GraphicsUnit.Inch, g.PageUnit, "SetSaveReset5");
Assert.AreEqual (PixelOffsetMode.Half, g.PixelOffsetMode, "SetSaveReset6");
Assert.AreEqual (new Point (10, 20), g.RenderingOrigin, "SetSaveReset7");
Assert.AreEqual (SmoothingMode.AntiAlias, g.SmoothingMode, "SetSaveReset8");
Assert.AreEqual (TextRenderingHint.ClearTypeGridFit, g.TextRenderingHint, "SetSaveReset9");
Assert.AreEqual (0, (int) g.ClipBounds.X, "SetSaveReset10");
Assert.AreEqual (0, (int) g.ClipBounds.Y, "SetSaveReset10");
g.Restore (state_default);
Assert.AreEqual (CompositingMode.SourceOver, g.CompositingMode, "SetSaveReset11");
Assert.AreEqual (CompositingQuality.Default, g.CompositingQuality, "SetSaveReset12");
Assert.AreEqual (InterpolationMode.Bilinear, g.InterpolationMode, "SetSaveReset13");
Assert.AreEqual (1, g.PageScale, "SetSaveReset14");
Assert.AreEqual (GraphicsUnit.Display, g.PageUnit, "SetSaveReset15");
Assert.AreEqual (PixelOffsetMode.Default, g.PixelOffsetMode, "SetSaveReset16");
Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "SetSaveReset17");
Assert.AreEqual (SmoothingMode.None, g.SmoothingMode, "SetSaveReset18");
Assert.AreEqual (TextRenderingHint.SystemDefault, g.TextRenderingHint, "SetSaveReset19");
Region r = new Region ();
Assert.AreEqual (r.GetBounds (g), g.ClipBounds, "SetSaveReset20");
g.Dispose ();
}
示例6: GetTransformCellRect
private RectangleF GetTransformCellRect(int index)
{
RectangleF rect = GetCellRect(index);
Region region = new Region(rect);
region.Translate(AutoScrollPosition.X, AutoScrollPosition.Y);
rect = region.GetBounds(CreateGraphics());
return rect;
}
示例7: PaintForm
private void PaintForm(Graphics g, Region clip)
{
if (!clip.GetBounds(g).Equals(UpdateRegion.GetBounds(g)))
UpdateRegion.Union(clip);
DrawBackground(g);
Opacity = Layout.Settings.Opacity;
if (Layout.Settings.AntiAliasing)
g.TextRenderingHint = TextRenderingHint.AntiAlias;
else
g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
g.CompositingQuality = CompositingQuality.GammaCorrected;
g.InterpolationMode = InterpolationMode.Bilinear;
g.SmoothingMode = SmoothingMode.AntiAlias;
ComponentRenderer.CalculateOverallSize(Layout.Mode);
var scaleFactor = Layout.Mode == LayoutMode.Vertical
? Height / Math.Max(ComponentRenderer.OverallSize, 1f)
: Width / Math.Max(ComponentRenderer.OverallSize, 1f);
g.ResetTransform();
g.ScaleTransform(scaleFactor, scaleFactor);
float transformedWidth = Width;
float transformedHeight = Height;
if (Layout.Mode == LayoutMode.Vertical)
transformedWidth /= scaleFactor;
else
transformedHeight /= scaleFactor;
BackColor = Color.Black;
ComponentRenderer.Render(g, CurrentState, transformedWidth, transformedHeight, Layout.Mode, UpdateRegion);
var currentSize = ComponentRenderer.OverallSize;
if (OldSize >= 0)
{
if (OldSize != currentSize)
{
MinimumSize = new Size(0, 0);
if (Layout.Mode == LayoutMode.Vertical)
Height = (int)((currentSize / (double)OldSize) * Height + 0.5);
else
Width = (int)((currentSize / (double)OldSize) * Width + 0.5);
}
FixSize();
if (Layout.Mode == LayoutMode.Vertical)
MinimumSize = new Size(100, (int)((ComponentRenderer.OverallSize / 3) + 0.5f));
else
MinimumSize = new Size((int)((ComponentRenderer.OverallSize / 3) + 0.5f), 25);
}
else
{
if (Layout.Mode == LayoutMode.Vertical)
Size = new Size(Layout.VerticalWidth, Layout.VerticalHeight);
else
Size = new Size(Layout.HorizontalWidth, Layout.HorizontalHeight);
OldSize++;
}
if (OldSize >= 0)
OldSize = currentSize;
}
示例8: PaintForm
private void PaintForm(Graphics g, Region clip)
{
if (CurrentState.LayoutSettings.BackgroundColor != Color.Transparent
|| CurrentState.LayoutSettings.BackgroundGradient != GradientType.Plain
&& CurrentState.LayoutSettings.BackgroundColor2 != Color.Transparent)
{
var gradientBrush = new LinearGradientBrush(
new PointF(0, 0),
CurrentState.LayoutSettings.BackgroundGradient == GradientType.Horizontal
? new PointF(this.Size.Width, 0)
: new PointF(0, this.Size.Height),
CurrentState.LayoutSettings.BackgroundColor,
CurrentState.LayoutSettings.BackgroundGradient == GradientType.Plain
? CurrentState.LayoutSettings.BackgroundColor
: CurrentState.LayoutSettings.BackgroundColor2);
g.FillRectangle(gradientBrush, 0, 0, this.Size.Width, this.Size.Height);
}
this.Opacity = Layout.Settings.Opacity;
if (Layout.Settings.AntiAliasing)
g.TextRenderingHint = TextRenderingHint.AntiAlias;
else
g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
g.CompositingQuality = CompositingQuality.GammaCorrected;
g.InterpolationMode = InterpolationMode.Bilinear;
g.SmoothingMode = SmoothingMode.AntiAlias;
var scaleFactor = Layout.Mode == LayoutMode.Vertical
? (float)this.Height / Math.Max(ComponentRenderer.OverallHeight, 1f)
: (float)this.Width / Math.Max(ComponentRenderer.OverallWidth, 1f);
g.ResetTransform();
g.ScaleTransform(scaleFactor, scaleFactor);
float transformedWidth = this.Width;
float transformedHeight = this.Height;
if (Layout.Mode == LayoutMode.Vertical)
transformedWidth /= scaleFactor;
else
transformedHeight /= scaleFactor;
this.BackColor = Color.Black;
if (!clip.GetBounds(g).Equals(UpdateRegion.GetBounds(g)))
UpdateRegion.Union(clip);
/*if (!CurrentState.DrawLock.TryEnterReadLock(500))
return;*/
ComponentRenderer.Render(g, CurrentState, transformedWidth, transformedHeight, Layout.Mode, UpdateRegion);
//CurrentState.DrawLock.ExitReadLock();
var currentSize = Layout.Mode == LayoutMode.Vertical ? ComponentRenderer.OverallHeight : ComponentRenderer.OverallWidth;
if (OldSize >= 0)
{
if (OldSize != currentSize)
{
this.MinimumSize = new Size(0, 0);
if (Layout.Mode == LayoutMode.Vertical)
this.Height = (int)((currentSize / (double)OldSize) * this.Height + 0.5);
else
this.Width = (int)((currentSize / (double)OldSize) * this.Width + 0.5);
}
FixSize();
if (Layout.Mode == LayoutMode.Vertical)
this.MinimumSize = new Size(100, (int)((ComponentRenderer.OverallHeight / 2) * (100 / Math.Max(100, ComponentRenderer.MinimumWidth)) + 0.5f));
else
this.MinimumSize = new Size((int)((ComponentRenderer.OverallWidth / 2) * (25 / Math.Max(25, ComponentRenderer.MinimumHeight)) + 0.5f), 25);
}
else
{
if (Layout.Mode == LayoutMode.Vertical)
this.Size = new Size(Layout.VerticalWidth, Layout.VerticalHeight);
else
this.Size = new Size(Layout.HorizontalWidth, Layout.HorizontalHeight);
OldSize++;
}
if (OldSize == 0)
RefreshesRemaining = 10;
if (OldSize >= 0)
OldSize = currentSize;
}
示例9: PushClip
/// <summary>
/// Overridden. PiccoloDirect3D only supports rectangular clip regions. So, if a
/// non-rectangular region is pushed, the bounds of that region will be used instead.
/// </summary>
/// <param name="aClip">The clip to push.</param>
public override void PushClip(Region aClip) {
PushClip(aClip.GetBounds(graphics));
}
示例10: foreach
/*public void ResetPoly()
{
SvgElementCollection col= tlVectorControl1.SVGDocument.SelectCollection;
if(col.Count<1){
return;
}
SvgElementCollection.ISvgElementEnumerator enumerator1 = tlVectorControl1.DrawArea.ElementList.GetEnumerator();
foreach(SvgElement ele in col){
if (ele.GetType().ToString() == "ItopVector.Core.Figure.Polygon")
{
glebeProperty p=new glebeProperty();
p.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
p.EleID = ((IGraph)ele).ID;
p = Services.BaseService.GetObject("SelectglebePropertyByEleID", p);
if(p!=null){
PointF[] tfArray1 = TLMath.getPolygonPoints(ele);
GraphicsPath selectAreaPath = new GraphicsPath();
selectAreaPath.AddLines(tfArray1);
selectAreaPath.CloseFigure();
Region region1 = new Region(selectAreaPath);
while (enumerator1.MoveNext())
{
IGraph graph1 = (IGraph)enumerator1.Current;
GraphicsPath path1 = (GraphicsPath)graph1.GPath.Clone();
path1.Transform(graph1.GraphTransform.Matrix);
Region region2 = new Region(path1);
region2.Intersect(region1);
if (!region2.GetBounds(Graphics.FromHwnd(IntPtr.Zero)).IsEmpty)
{
glebeProperty p1 = new glebeProperty();
p1.SvgUID = tlVectorControl1.SVGDocument.SvgdataUid;
p1.EleID = graph1.ID;
p1 = Services.BaseService.GetObject("SelectglebePropertyByEleID", p1);
if(p1!=null){
p1.ParentEleID = p.UID;
Services.BaseService.Update("UpdateglebePropertyAreaAll", p1);
}
}
}
}
}
}
MessageBox.Show("更新完成。","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}*/
private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
try
{
if (e.ClickedItem.Text == "屬性")
{
XmlElement xml1 = (XmlElement)tlVectorControl1.SVGDocument.CurrentElement;
//PointF[] pf = TLMath.getPolygonPoints(xml1);
DeviceHelper.xml1 = xml1;
//((Polygon)xml1).Transform.Matrix.TransformPoints(pf);
// 規劃
if (getlayer(SvgDocument.currentLayer, "電網規劃層", tlVectorControl1.SVGDocument.getLayerList()))
{
if (xml1 == null || tlVectorControl1.SVGDocument.CurrentElement.ID == "svg")
{
MessageBox.Show("請先選擇規劃區域。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (tlVectorControl1.SVGDocument.CurrentElement.GetType().ToString() == "ItopVector.Core.Figure.RectangleElement")
{
//frmImgManager frm = new frmImgManager();
//frm.Show();
}
if (tlVectorControl1.SVGDocument.CurrentElement.GetType().ToString() == "ItopVector.Core.Figure.Polygon")
{
XmlNodeList n1 = tlVectorControl1.SVGDocument.GetElementsByTagName("use");
PointF[] tfArray1 = TLMath.getPolygonPoints(xml1);
string str220 = "";
string str110 = "";
string str66 = "";
string str_id = "";
GraphicsPath selectAreaPath = new GraphicsPath();
selectAreaPath.AddLines(tfArray1);
selectAreaPath.CloseFigure();
//Matrix x=new Matrix(
//Region region1 = new Region(selectAreaPath);
for (int i = 0; i < n1.Count; i++)
{
float OffX = 0f;
float OffY = 0f;
bool ck = false;
Use use = (Use)n1[i];
if (use.GetAttribute("xlink:href").Contains("byq") || use.GetAttribute("xlink:href").Contains("pds"))
{
if (selectAreaPath.IsVisible(use.CenterPoint))
{
if (use.GetAttribute("Deviceid") != "")
{
str_id = str_id + "'" + use.GetAttribute("Deviceid") + "',";
}
}
}
if (use.GetAttribute("xlink:href").Contains("Substation"))
{
//.........這裏部分代碼省略.........
示例11: InfinityIntersectTransform
public void InfinityIntersectTransform ()
{
using (Region r = new Region ()) {
Assert.IsTrue (r.IsInfinite (graphic), "before");
r.Intersect (new Rectangle (-10, -10, 20, 20));
using (Matrix m = new Matrix (2, 0, 0, 0.5f, 10, 10)) {
r.Transform (m);
}
RectangleF bounds = r.GetBounds (graphic);
Assert.AreEqual (-10, bounds.X, "X");
Assert.AreEqual (5, bounds.Y, "Y");
Assert.AreEqual (40, bounds.Width, "Width");
Assert.AreEqual (10, bounds.Height, "Height");
}
}
示例12: InfinityIntersectTranslate
public void InfinityIntersectTranslate ()
{
using (Region r = new Region ()) {
Assert.IsTrue (r.IsInfinite (graphic), "before");
r.Intersect (new Rectangle (-10, -10, 20, 20));
r.Translate (10, 10);
RectangleF bounds = r.GetBounds (graphic);
Assert.AreEqual (0, bounds.X, "X");
Assert.AreEqual (0, bounds.Y, "Y");
Assert.AreEqual (20, bounds.Width, "Width");
Assert.AreEqual (20, bounds.Height, "Height");
}
}
示例13: InfinityExclude
public void InfinityExclude ()
{
using (Region r = new Region ()) {
Assert.IsTrue (r.IsInfinite (graphic), "before");
r.Exclude (new Rectangle (5, 5, 10, 10));
Assert.IsFalse (r.IsInfinite (graphic), "after");
RectangleF bounds = r.GetBounds (graphic);
Assert.AreEqual (-4194304, bounds.X, "X");
Assert.AreEqual (-4194304, bounds.Y, "Y");
Assert.AreEqual (8388608, bounds.Width, "Width");
Assert.AreEqual (8388608, bounds.Height, "Height");
}
}
示例14: Animator06
// 原理:將圖像分為正方形塊,然後計算所有分塊按照奇偶從左到右顯示或從右到左顯示所需的區域,並用材質畫刷填充
private void Animator06()
{
const float blockSize = 70; // 正方塊的邊長
const int showWidth = 1; // 每次顯示的像素列數
try
{
OnDrawStarted(this, EventArgs.Empty);
ClearBackground();
// 建立空區域,如使用Region的無參構造函數則建立一個無限大小的區域,而非空區域
Region region = new Region(new GraphicsPath());
// 建立位圖材質畫刷
TextureBrush textureBrush = new TextureBrush(bmp);
// 分塊的行坐標+列坐標為偶數則從左到右逐列顯示本塊,否則從右到左逐列顯示本塊
for (int i = 0; i <= Math.Ceiling(blockSize / showWidth); i++)
{
for (int x = 0; x < Math.Ceiling(bmp.Width / blockSize); x++)
{
for (int y = 0; y < Math.Ceiling(bmp.Height / blockSize); y++)
{
RectangleF rect;
// 判斷塊的行列坐標和為奇數或偶數
if ((x + y) % 2 == 0)
{
rect = new RectangleF(x * blockSize + i * showWidth, y * blockSize, showWidth, blockSize);
}
else
{
rect = new RectangleF((x + 1) * blockSize - i * showWidth, y * blockSize, showWidth, blockSize);
}
region.Union(rect); // 將要顯示的區域合並到region中
}
}
dc.FillRegion(textureBrush, region); // 使用材質畫刷填充區域
ShowBmp(region.GetBounds(dc));
Thread.Sleep(10 * delay);
}
}
catch (Exception ex)
{
ShowError(ex.Message);
}
finally
{
OnDrawCompleted(this, EventArgs.Empty);
}
}
示例15: Animator03
// 原理:由大到小生成圖像中心區域,然後用總區域減去該中心區域,並用材質畫刷填充
private void Animator03()
{
const float stepCount = 4; // 每次收縮的步長像素
try
{
OnDrawStarted(this, EventArgs.Empty);
ClearBackground();
// 建立空區域,如使用Region的無參構造函數則建立一個無限大小的區域,而非空區域
Region region = new Region(new GraphicsPath());
// 建立位圖材質畫刷
TextureBrush textureBrush = new TextureBrush(bmp);
for (float x = 0; x <= bmp.Width / 2f; x += stepCount)
{
// 添加整個位圖區域
region.Union(new Rectangle(0, 0, bmp.Width, bmp.Height));
// 從中心開始,由大到小填充背景色或填充縮小尺寸的原圖
// 計算高度變化量,如果寬度大,則高度變化量小於寬度,否則大於寬度
float y = x * bmp.Height / bmp.Width;
RectangleF rect = new RectangleF(x, y, bmp.Width - 2f * x, bmp.Height - 2f * y);
// 計算整個位圖區域與背景色區域的差集
region.Exclude(rect);
dc.FillRegion(textureBrush, region); // 使用材質畫刷填充區域
ShowBmp(region.GetBounds(dc));
Thread.Sleep(10 * delay);
}
// 由於stepCount可能無法被寬度整除,則最終生成的背景色區域並不為空,故在循環結束後繪製整個位圖
dc.DrawImage(bmp, 0, 0);
ShowBmp();
}
catch (Exception ex)
{
ShowError(ex.Message);
}
finally
{
OnDrawCompleted(this, EventArgs.Empty);
}
}