在 .NET、C# 中绘制形状的形状线问题

发布于 2024-11-07 15:23:44 字数 2197 浏览 0 评论 0原文

我想画一个有方形、菱形、十字形的形状。方形线条扎实、细腻。然而,菱形和十字形的线看起来都像虚线或点线。我希望所有形状都有实线。

有什么想法吗?

下面是代码和形状:

http://www.sendspace.com/file/n3wljs

private void CreateVariousShapes()
{
    Bitmap bitmap = new Bitmap(17, 17);
    Graphics graphics = Graphics.FromImage(bitmap);
    Pen pen = new Pen(Color.Black);
    pen.Width = 1;
    pen.DashStyle = DashStyle.Solid;
    Brush brush = new SolidBrush(Color.White);

    //graphics.FillRectangle(brush, 0, 0, 16, 16);

    //graphics.DrawRectangle(pen, 0, 0, 16, 16);

    FillDiamond(brush, graphics);
    DrawDiamond(pen, graphics);

    DrawCross(pen, graphics);

    //bitmap.Save(MapPath("SquareDiamondCross.png"),ImageFormat.Png);
    //bitmap.Save(MapPath("SquareCross.png"), ImageFormat.Png);
    //bitmap.Save(MapPath("SquareDiamond.png"), ImageFormat.Png);
    bitmap.Save(MapPath("DiamondCross.png"), ImageFormat.Png);
}

private void FillDiamond(Brush brush, Graphics graphics)
{
    Point[] points = new Point[]
                        { new Point(0,8), 
                        new Point(8,16), 
                        new Point(16,8), 
                        new Point(8,0), 

                        };

    graphics.FillPolygon(brush, points);
}

private void DrawDiamond(Pen pen, Graphics graphics)
{
    Point[] points = new Point[]
                        { new Point(0,8), 
                        new Point(8,16), 
                        new Point(16,8), 
                        new Point(8,0), 
                        };
    graphics.DrawPolygon(pen, points);
}

private void DrawCross(Pen pen, Graphics graphics)
{
    graphics.DrawLine(pen, 4, 2, 2, 4);

    graphics.DrawLine(pen, 2, 12, 4, 14);

    graphics.DrawLine(pen, 12, 14, 14, 12);

    graphics.DrawLine(pen, 12, 2, 14, 4);

    graphics.DrawLine(pen, 2, 4, 6, 8);
    graphics.DrawLine(pen, 2, 12, 6, 8);

    graphics.DrawLine(pen, 4, 14, 8, 10);
    graphics.DrawLine(pen, 12, 14, 8, 10);

    graphics.DrawLine(pen, 14, 12, 10, 8);
    graphics.DrawLine(pen, 14, 4, 10, 8);

    graphics.DrawLine(pen, 12, 2, 8, 6);
    graphics.DrawLine(pen, 4, 2, 8, 6);
}

I want to draw a shape with square, diamond, and cross shape. The square line is solid, and fine. However, the line of both diamond and cross look like dashed or dotted. I want all shapes have solid line.

Any ideas?

Below is the code, and shapes:

http://www.sendspace.com/file/n3wljs

private void CreateVariousShapes()
{
    Bitmap bitmap = new Bitmap(17, 17);
    Graphics graphics = Graphics.FromImage(bitmap);
    Pen pen = new Pen(Color.Black);
    pen.Width = 1;
    pen.DashStyle = DashStyle.Solid;
    Brush brush = new SolidBrush(Color.White);

    //graphics.FillRectangle(brush, 0, 0, 16, 16);

    //graphics.DrawRectangle(pen, 0, 0, 16, 16);

    FillDiamond(brush, graphics);
    DrawDiamond(pen, graphics);

    DrawCross(pen, graphics);

    //bitmap.Save(MapPath("SquareDiamondCross.png"),ImageFormat.Png);
    //bitmap.Save(MapPath("SquareCross.png"), ImageFormat.Png);
    //bitmap.Save(MapPath("SquareDiamond.png"), ImageFormat.Png);
    bitmap.Save(MapPath("DiamondCross.png"), ImageFormat.Png);
}

private void FillDiamond(Brush brush, Graphics graphics)
{
    Point[] points = new Point[]
                        { new Point(0,8), 
                        new Point(8,16), 
                        new Point(16,8), 
                        new Point(8,0), 

                        };

    graphics.FillPolygon(brush, points);
}

private void DrawDiamond(Pen pen, Graphics graphics)
{
    Point[] points = new Point[]
                        { new Point(0,8), 
                        new Point(8,16), 
                        new Point(16,8), 
                        new Point(8,0), 
                        };
    graphics.DrawPolygon(pen, points);
}

private void DrawCross(Pen pen, Graphics graphics)
{
    graphics.DrawLine(pen, 4, 2, 2, 4);

    graphics.DrawLine(pen, 2, 12, 4, 14);

    graphics.DrawLine(pen, 12, 14, 14, 12);

    graphics.DrawLine(pen, 12, 2, 14, 4);

    graphics.DrawLine(pen, 2, 4, 6, 8);
    graphics.DrawLine(pen, 2, 12, 6, 8);

    graphics.DrawLine(pen, 4, 14, 8, 10);
    graphics.DrawLine(pen, 12, 14, 8, 10);

    graphics.DrawLine(pen, 14, 12, 10, 8);
    graphics.DrawLine(pen, 14, 4, 10, 8);

    graphics.DrawLine(pen, 12, 2, 8, 6);
    graphics.DrawLine(pen, 4, 2, 8, 6);
}

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

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

发布评论

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

评论(1

红玫瑰 2024-11-14 15:23:44

设置以下图形属性:

graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = SmoothingMode.HighQuality;

希望您能得到您想要的。

Set the following graphics properties:

graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = SmoothingMode.HighQuality;

Hopefully you will get what you want.

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