【问题标题】:Shape line issue with drawing shape in .NET, c#在.NET,c#中绘制形状的形状线问题
【发布时间】:2011-08-26 21:10:50
【问题描述】:

我想画一个正方形、菱形和十字形的形状。方线是实心的,很好。然而,菱形线和十字线看起来像虚线或点线。我希望所有形状都有实线。

有什么想法吗?

下面是代码和形状:

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);
}

【问题讨论】:

  • 看起来像一个抗锯齿问题...(缺少)

标签: c# .net image drawing gdi


【解决方案1】:

设置以下图形属性:

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

希望你能得到你想要的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-09
    • 1970-01-01
    • 2012-12-04
    • 1970-01-01
    相关资源
    最近更新 更多