本文整理汇总了C#中Fragment.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Fragment.Dispose方法的具体用法?C# Fragment.Dispose怎么用?C# Fragment.Dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Fragment
的用法示例。
在下文中一共展示了Fragment.Dispose方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Template
//.........这里部分代码省略.........
var rightSide = Max(vTopRight.Width, right.Width, vBottomRight.Width);
var bottomSide = Max(vBottomLeft.Height, bottom.Height, vBottomRight.Height);
// Since we're having two types of corners, we need a place for all of them.
// So, we could scale sides and store 4 corners inside of square.
left.Scale(0, topSide + bottomSide);
right.Scale(0, topSide + bottomSide);
top.Scale(leftSide + bottomSide, 0);
bottom.Scale(leftSide + bottomSide, 0);
// Creating bitmap, that will contain all eight corners and four sides
Bitmap = new Bitmap((leftSide + rightSide) * 2, (topSide + bottomSide) * 2, PixelFormat.Format32bppArgb);
// Calculating inner rectangle, that will be used as a parameter for Metrics
InnerRectangle = new Rectangle {
X = leftSide,
Y = topSide,
Width = leftSide + rightSide,
Height = topSide + bottomSide
};
// Metrics contain information about each fragment on bitmap, and we're
// creating metrics in order to draw each fragment onto bitmap, simple.
Metrics = new Metrics(Bitmap.Size, InnerRectangle);
// ...
using (var g = Graphics.FromImage(Bitmap)) {
// Sides
g.DrawImage(top.Bitmap, Metrics.Top, new Rectangle(Point.Empty, top.Size), GraphicsUnit.Pixel);
g.DrawImage(bottom.Bitmap, Metrics.Bottom, new Rectangle(Point.Empty, bottom.Size), GraphicsUnit.Pixel);
g.DrawImage(left.Bitmap, Metrics.Left, new Rectangle(Point.Empty, left.Size), GraphicsUnit.Pixel);
g.DrawImage(right.Bitmap, Metrics.Right, new Rectangle(Point.Empty, right.Size), GraphicsUnit.Pixel);
// Corners for vertical sides
g.DrawImage(vTopLeft.Bitmap, Metrics.Vertical.TopLeft, new Rectangle(Point.Empty, vTopLeft.Size), GraphicsUnit.Pixel);
g.DrawImage(vTopRight.Bitmap, Metrics.Vertical.TopRight, new Rectangle(Point.Empty, vTopRight.Size), GraphicsUnit.Pixel);
g.DrawImage(vBottomLeft.Bitmap, Metrics.Vertical.BottomLeft, new Rectangle(Point.Empty, vBottomLeft.Size), GraphicsUnit.Pixel);
g.DrawImage(vBottomRight.Bitmap, Metrics.Vertical.BottomRight, new Rectangle(Point.Empty, vBottomRight.Size), GraphicsUnit.Pixel);
// Corners for horizontal sides
g.DrawImage(hTopLeft.Bitmap, Metrics.Horizontal.TopLeft, new Rectangle(Point.Empty, vTopLeft.Size), GraphicsUnit.Pixel);
g.DrawImage(hTopRight.Bitmap, Metrics.Horizontal.TopRight, new Rectangle(Point.Empty, vTopRight.Size), GraphicsUnit.Pixel);
g.DrawImage(hBottomLeft.Bitmap, Metrics.Horizontal.BottomLeft, new Rectangle(Point.Empty, vBottomLeft.Size), GraphicsUnit.Pixel);
g.DrawImage(hBottomRight.Bitmap, Metrics.Horizontal.BottomRight, new Rectangle(Point.Empty, vBottomRight.Size), GraphicsUnit.Pixel);
}
// After we're done with creating result-bitmap, we can dispose from each fragment
hTopLeft.Dispose();
hTopRight.Dispose();
hBottomLeft.Dispose();
hBottomRight.Dispose();
// ...
vTopLeft.Dispose();
vTopRight.Dispose();
vBottomLeft.Dispose();
vBottomRight.Dispose();
// ...
left.Dispose();
right.Dispose();
top.Dispose();
bottom.Dispose();
// Developer could specify margin manually, but it will take time to get it right.
// So, instead of manual setup, we're using bitmap, that contains two types of pixels:
// one pixels are fully transparent (Color.A == 0), the other one opaque (Color.A = 255).
// Using the same class to cut and trim fragments, we can calculate what we need.
if (marginMask != null) {
// Creating fragments from sides (top, bottom, left, right)
var topBitmap = new Fragment(marginMask, new Rectangle(width, 0, width, height), true);
var bottomBitmap = new Fragment(marginMask, new Rectangle(width, height*2, width, height), true);
var leftBitmap = new Fragment(marginMask, new Rectangle(0, height, width, height), true);
var rightBitmap = new Fragment(marginMask, new Rectangle(width*2, height, width, height), true);
// ...
Margin = new Padding(-leftBitmap.Width, -topBitmap.Height, -(rightBitmap.Width + 1), -(bottomBitmap.Height + 1));
// ...
topBitmap.Dispose();
bottomBitmap.Dispose();
leftBitmap.Dispose();
rightBitmap.Dispose();
} else {
// In this case, bitmap wasn't specified, so, margin will be empty. In this case,
// developer can open testing form and tweak margin on each side manually.
Margin = Padding.Empty;
}
// Final steps, creating theme and form. From now, developer can test generated
// bitmap and see, what's wrong and what's not.
Theme = new Theme(Bitmap, Metrics, Margin);
Form = new TestingForm(this);
}