带有分隔符图案的纹理画笔

发布于 2024-12-03 03:46:46 字数 1315 浏览 3 评论 0原文

需要一个方法来返回变量Texturebrush。该方法需要重载:

Size AreaSize,
int HorizontalSeperatorCount,
int VerticalSeperatorCount,
int SeperatorWidth,
Brush Seperatorbackground,
Brush Rectanglebackground,

矩形的大小将自动计算


TextturebrushExample1

这些示例具有以下值

Size AreaSize = new Size(100, 100),
int HorizontalSeperatorCount = 1,
int VerticalSeperatorCount = 1,
int SeperatorWidth = 10,
Brush Seperatorbackground = Brushes.Grey,
Brush Rectanglebackground = Brushes.Red

TextturebrushExample2

第二个示例具有不同的 VerticalSeperatorCount

Size AreaSize = new Size(100, 100),
int HorizontalSeperatorCount = 1,
int VerticalSeperatorCount = 3,
int SeperatorWidth = 10,
Brush Seperatorbackground = Brushes.Grey,
Brush Rectanglebackground = Brushes.Red

方法的签名,

public static TextureBrush GetTextureBrush(Size areaSize, int horizontalSeperator, int verticalSeperatorCount, int seperatorWidth, Brush seperatorBackground, Brush rectangleBackground)

Texturebrush 将是用于填充窗口

TextturebrushExample3

我不擅长绘图。 我会非常非常高兴有一个解决方案。

need a Method to return a variable Texturebrush. The method need to be overloaded with:

Size AreaSize,
int HorizontalSeperatorCount,
int VerticalSeperatorCount,
int SeperatorWidth,
Brush Seperatorbackground,
Brush Rectanglebackground,

The size of the rectangle will be calculated automatically


TextturebrushExample1

These example have following values

Size AreaSize = new Size(100, 100),
int HorizontalSeperatorCount = 1,
int VerticalSeperatorCount = 1,
int SeperatorWidth = 10,
Brush Seperatorbackground = Brushes.Grey,
Brush Rectanglebackground = Brushes.Red

TextturebrushExample2

The second example have a different VerticalSeperatorCount

Size AreaSize = new Size(100, 100),
int HorizontalSeperatorCount = 1,
int VerticalSeperatorCount = 3,
int SeperatorWidth = 10,
Brush Seperatorbackground = Brushes.Grey,
Brush Rectanglebackground = Brushes.Red

The signatur of the method

public static TextureBrush GetTextureBrush(Size areaSize, int horizontalSeperator, int verticalSeperatorCount, int seperatorWidth, Brush seperatorBackground, Brush rectangleBackground)

The Texturebrush will be used to fill a window

TextturebrushExample3

I'm not the best at the drawing stuff.
I would be very very happy about a solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海的爱人是光 2024-12-10 03:46:46
public static TextureBrush GetSeperatorBrush(Size areaSize,
    int horizontalSeperatorCount,
    int verticalSeperatorCount,
    int seperatorWidth,
    Brush rectangleBackground)
{
    var horizontalRectangleCount = horizontalSeperatorCount + 1.0f;
    var verticalRectangleCount = verticalSeperatorCount + 1.0f;

    var horizontalSeperatorBreadths = (horizontalSeperatorCount + 2.0f) * seperatorWidth;
    var verticalSeperatorBreadths = (verticalSeperatorCount + 2.0f) * seperatorWidth;

    var rectangleWidth = (areaSize.Width - verticalSeperatorBreadths) / verticalRectangleCount;
    var rectangleHeight = (areaSize.Height - horizontalSeperatorBreadths) / horizontalRectangleCount;

    var bitmap = new Bitmap((int)Math.Ceiling(rectangleWidth + seperatorWidth), (int)Math.Ceiling(rectangleHeight + seperatorWidth));
    var graphics = Graphics.FromImage(bitmap);

    var rectanglePoints = new[] { new PointF(seperatorWidth, seperatorWidth), 
        new PointF(seperatorWidth + rectangleWidth, seperatorWidth), 
        new PointF(seperatorWidth + rectangleWidth, seperatorWidth + rectangleHeight), 
        new PointF(seperatorWidth, seperatorWidth + rectangleHeight),
        new PointF(seperatorWidth, seperatorWidth)};

    graphics.FillPolygon(rectangleBackground, rectanglePoints);
    graphics.Dispose();

    var textureBrush = new TextureBrush(bitmap, System.Drawing.Drawing2D.WrapMode.Tile);
    return textureBrush;
}

由于四舍五入,过多的分隔符会带来一些麻烦。对我来说没问题。

public static TextureBrush GetSeperatorBrush(Size areaSize,
    int horizontalSeperatorCount,
    int verticalSeperatorCount,
    int seperatorWidth,
    Brush rectangleBackground)
{
    var horizontalRectangleCount = horizontalSeperatorCount + 1.0f;
    var verticalRectangleCount = verticalSeperatorCount + 1.0f;

    var horizontalSeperatorBreadths = (horizontalSeperatorCount + 2.0f) * seperatorWidth;
    var verticalSeperatorBreadths = (verticalSeperatorCount + 2.0f) * seperatorWidth;

    var rectangleWidth = (areaSize.Width - verticalSeperatorBreadths) / verticalRectangleCount;
    var rectangleHeight = (areaSize.Height - horizontalSeperatorBreadths) / horizontalRectangleCount;

    var bitmap = new Bitmap((int)Math.Ceiling(rectangleWidth + seperatorWidth), (int)Math.Ceiling(rectangleHeight + seperatorWidth));
    var graphics = Graphics.FromImage(bitmap);

    var rectanglePoints = new[] { new PointF(seperatorWidth, seperatorWidth), 
        new PointF(seperatorWidth + rectangleWidth, seperatorWidth), 
        new PointF(seperatorWidth + rectangleWidth, seperatorWidth + rectangleHeight), 
        new PointF(seperatorWidth, seperatorWidth + rectangleHeight),
        new PointF(seperatorWidth, seperatorWidth)};

    graphics.FillPolygon(rectangleBackground, rectanglePoints);
    graphics.Dispose();

    var textureBrush = new TextureBrush(bitmap, System.Drawing.Drawing2D.WrapMode.Tile);
    return textureBrush;
}

Make some trouble with to much seperators because of the rounding . It's ok for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文