本文整理汇总了C#中Fragment.Scale方法的典型用法代码示例。如果您正苦于以下问题:C# Fragment.Scale方法的具体用法?C# Fragment.Scale怎么用?C# Fragment.Scale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Fragment
的用法示例。
在下文中一共展示了Fragment.Scale方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Template
/// <summary>Default constructor.</summary>
/// <param name="template"><see cref="System.Drawing.Bitmap"/>, that will be used as a template.</param>
/// <param name="marginMask"><see cref="System.Drawing.Bitmap"/>, that reprensets a map with two colors (transparent and opaque) and used to determine margin (<see cref="System.Windows.Forms.Padding"/>).</param>
/// <param name="gradientWidth">Minumum width or height of gradient.</param>
public Template(Bitmap template, Bitmap marginMask = null, int gradientWidth = 20)
{
// Basicly, we're cutting each fragment from provided template, then triming each
// side in order to get rid of empty space. After that, we're drawing onto new
// bitmap those fragments and creating everything we need to launch the test.
// Provided bitmap must have specific size, so we could divide it onto three parts
// horizontally and vertically. A little later, we're checking results...
var width = template.Width / 3;
var height = template.Height / 3;
// ...and throwing exception, if something wrong
if ((width%1) != 0 || (height%1) != 0) {
throw new Exception($"Width or height of provided bitmap wrong. Width / 3: {width}; Height / 3: {height}");
}
// Here we might ignore it, but when updating layered windows, there might be problems.
if (template.PixelFormat != PixelFormat.Format32bppArgb) {
throw new Exception("Pixel format of provided bitmap not equals PixelFormat.Format32bppArgb");
}
// Creating fragments of corners for horizontal sides
var hTopLeft = new Fragment(template, new Rectangle(0, 0, width, height), true);
var hTopRight = new Fragment(template, new Rectangle(width * 2, 0, width, height), true);
var hBottomLeft = new Fragment(template, new Rectangle(0, height * 2, width, height), true);
var hBottomRight = new Fragment(template, new Rectangle(width * 2, height * 2, width, height), true);
// Creating fragments of corners for vertical sides
var vTopLeft = new Fragment(template, new Rectangle(0, 0, width, height), true);
var vTopRight = new Fragment(template, new Rectangle(width * 2, 0, width, height), true);
var vBottomLeft = new Fragment(template, new Rectangle(0, height * 2, width, height), true);
var vBottomRight = new Fragment(template, new Rectangle(width * 2, height * 2, width, height), true);
// Creating fragments of sides
var left = new Fragment(template, new Rectangle(0, height, width, height), true);
var right = new Fragment(template, new Rectangle(width * 2, height, width, height), true);
var top = new Fragment(template, new Rectangle(width, 0, width, height), true);
var bottom = new Fragment(template, new Rectangle(width, height * 2, width, height), true);
// You can't move several layered windows simultaniusly, even DeferWindowPos fails.
// But we could create specific mask, that will cover any delays in movement
// Generating and applying mask to each corner
hTopLeft.ApplyMask(MaskType.HTopLeft, gradientWidth);
hTopRight.ApplyMask(MaskType.HTopRight, gradientWidth);
hBottomLeft.ApplyMask(MaskType.HBottomLeft, gradientWidth);
hBottomRight.ApplyMask(MaskType.HBottomRight, gradientWidth);
// ...
vTopLeft.ApplyMask(MaskType.VTopLeft, gradientWidth);
vTopRight.ApplyMask(MaskType.VTopRight, gradientWidth);
vBottomLeft.ApplyMask(MaskType.VBottomLeft, gradientWidth);
vBottomRight.ApplyMask(MaskType.VBottomRight, gradientWidth);
// Calculating maximum size of each side. This will be used during scaling sides and
// creating inner rectangle. Last thing will be used in order to create Metrics.
var leftSide = Max(vTopLeft.Width, left.Width, vBottomLeft.Width);
var topSide = Max(vTopLeft.Height, top.Height, vTopRight.Height);
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);
//.........这里部分代码省略.........