* UGraphics: 重构了一遍绘图方法
This commit is contained in:
parent
e982882169
commit
32d7ed3a05
@ -17,6 +17,7 @@
|
||||
* 创建日期: 2020-08-20
|
||||
*
|
||||
* 2021-08-20: V3.0.6 整理了一些GDI绘图的常用方法扩展
|
||||
* 2023-03-28: V3.3.4 重构了一遍绘图方法
|
||||
******************************************************************************/
|
||||
|
||||
using System;
|
||||
@ -43,11 +44,10 @@ namespace Sunny.UI
|
||||
/// <param name="format">格式</param>
|
||||
public static void DrawString(this Graphics g, string text, Font font, Color color, RectangleF rect, StringFormat format)
|
||||
{
|
||||
using (Brush br = color.Brush())
|
||||
{
|
||||
if (text.IsNullOrEmpty()) return;
|
||||
using Brush br = color.Brush();
|
||||
g.DrawString(text, font, br, rect, format);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制字符串
|
||||
@ -59,11 +59,10 @@ namespace Sunny.UI
|
||||
/// <param name="rect">区域</param>
|
||||
public static void DrawString(this Graphics g, string text, Font font, Color color, RectangleF rect)
|
||||
{
|
||||
using (Brush br = color.Brush())
|
||||
{
|
||||
if (text.IsNullOrEmpty()) return;
|
||||
using Brush br = color.Brush();
|
||||
g.DrawString(text, font, br, rect);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制字符串
|
||||
@ -76,11 +75,10 @@ namespace Sunny.UI
|
||||
/// <param name="format">格式</param>
|
||||
public static void DrawString(this Graphics g, string text, Font font, Color color, Rectangle rect, StringFormat format)
|
||||
{
|
||||
using (Brush br = color.Brush())
|
||||
{
|
||||
if (text.IsNullOrEmpty()) return;
|
||||
using Brush br = color.Brush();
|
||||
g.DrawString(text, font, br, rect, format);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制字符串
|
||||
@ -92,11 +90,10 @@ namespace Sunny.UI
|
||||
/// <param name="rect">区域</param>
|
||||
public static void DrawString(this Graphics g, string text, Font font, Color color, Rectangle rect)
|
||||
{
|
||||
using (Brush br = color.Brush())
|
||||
{
|
||||
if (text.IsNullOrEmpty()) return;
|
||||
using Brush br = color.Brush();
|
||||
g.DrawString(text, font, br, rect);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制字符串
|
||||
@ -109,11 +106,10 @@ namespace Sunny.UI
|
||||
/// <param name="y">垂直位置</param>
|
||||
public static void DrawString(this Graphics g, string text, Font font, Color color, float x, float y)
|
||||
{
|
||||
using (Brush br = color.Brush())
|
||||
{
|
||||
if (text.IsNullOrEmpty()) return;
|
||||
using Brush br = color.Brush();
|
||||
g.DrawString(text, font, br, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制字符串
|
||||
@ -149,11 +145,9 @@ namespace Sunny.UI
|
||||
/// <param name="format">格式</param>
|
||||
public static void DrawString(this Graphics g, string text, Font font, Color color, float x, float y, StringFormat format)
|
||||
{
|
||||
using (Brush br = color.Brush())
|
||||
{
|
||||
using Brush br = color.Brush();
|
||||
g.DrawString(text, font, br, x, y, format);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制字符串
|
||||
@ -189,13 +183,11 @@ namespace Sunny.UI
|
||||
/// <param name="penWidth">笔宽</param>
|
||||
public static void DrawLines(this Graphics g, Color color, Point[] points, bool smooth = false, float penWidth = 1)
|
||||
{
|
||||
using (Pen pen = color.Pen(penWidth))
|
||||
{
|
||||
using Pen pen = color.Pen(penWidth);
|
||||
g.Smooth(smooth);
|
||||
g.DrawLines(pen, points);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制多条直线连接
|
||||
@ -207,13 +199,11 @@ namespace Sunny.UI
|
||||
/// <param name="penWidth">笔宽</param>
|
||||
public static void DrawLines(this Graphics g, Color color, PointF[] points, bool smooth = false, float penWidth = 1)
|
||||
{
|
||||
using (Pen pen = color.Pen(penWidth))
|
||||
{
|
||||
using Pen pen = color.Pen(penWidth);
|
||||
g.Smooth(smooth);
|
||||
g.DrawLines(pen, points);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制曲线
|
||||
@ -225,13 +215,11 @@ namespace Sunny.UI
|
||||
/// <param name="penWidth">笔宽</param>
|
||||
public static void DrawCurve(this Graphics g, Color color, Point[] points, bool smooth = false, float penWidth = 1)
|
||||
{
|
||||
using (Pen pen = color.Pen(penWidth))
|
||||
{
|
||||
using Pen pen = color.Pen(penWidth);
|
||||
g.Smooth(smooth);
|
||||
g.DrawCurve(pen, points);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制曲线
|
||||
@ -243,13 +231,11 @@ namespace Sunny.UI
|
||||
/// <param name="penWidth">笔宽</param>
|
||||
public static void DrawCurve(this Graphics g, Color color, PointF[] points, bool smooth = false, float penWidth = 1)
|
||||
{
|
||||
using (Pen pen = color.Pen(penWidth))
|
||||
{
|
||||
using Pen pen = color.Pen(penWidth);
|
||||
g.Smooth(smooth);
|
||||
g.DrawCurve(pen, points);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制直线
|
||||
@ -264,13 +250,11 @@ namespace Sunny.UI
|
||||
/// <param name="penWidth">笔宽</param>
|
||||
public static void DrawLine(this Graphics g, Color color, int x1, int y1, int x2, int y2, bool smooth = false, float penWidth = 1)
|
||||
{
|
||||
using (Pen pen = color.Pen(penWidth))
|
||||
{
|
||||
using Pen pen = color.Pen(penWidth);
|
||||
g.Smooth(smooth);
|
||||
g.DrawLine(pen, x1, y1, x2, y2);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制直线
|
||||
@ -298,14 +282,11 @@ namespace Sunny.UI
|
||||
public static void DrawLine(this Graphics g, Color color, float x1, float y1, float x2, float y2, bool smooth = false, float penWidth = 1)
|
||||
{
|
||||
if (y1.IsNanOrInfinity() || y2.IsNanOrInfinity() || x1.IsNanOrInfinity() || x2.IsNanOrInfinity()) return;
|
||||
|
||||
using (Pen pen = color.Pen(penWidth))
|
||||
{
|
||||
using Pen pen = color.Pen(penWidth);
|
||||
g.Smooth(smooth);
|
||||
g.DrawLine(pen, x1, y1, x2, y2);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制直线
|
||||
@ -334,13 +315,11 @@ namespace Sunny.UI
|
||||
/// <param name="penWidth">笔宽</param>
|
||||
public static void DrawArc(this Graphics g, Color color, int x, int y, int width, int height, int startAngle, int sweepAngle, bool smooth = true, float penWidth = 1)
|
||||
{
|
||||
using (Pen pen = color.Pen(penWidth))
|
||||
{
|
||||
using Pen pen = color.Pen(penWidth);
|
||||
g.Smooth(smooth);
|
||||
g.DrawArc(pen, x, y, width, height, startAngle, sweepAngle);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制弧线
|
||||
@ -357,13 +336,11 @@ namespace Sunny.UI
|
||||
/// <param name="penWidth">笔宽</param>
|
||||
public static void DrawArc(this Graphics g, Color color, float x, float y, float width, float height, float startAngle, float sweepAngle, bool smooth = true, float penWidth = 1)
|
||||
{
|
||||
using (Pen pen = color.Pen(penWidth))
|
||||
{
|
||||
using Pen pen = color.Pen(penWidth);
|
||||
g.Smooth(smooth);
|
||||
g.DrawArc(pen, x, y, width, height, startAngle, sweepAngle);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制弧线
|
||||
@ -408,13 +385,11 @@ namespace Sunny.UI
|
||||
/// <param name="penWidth">笔宽</param>
|
||||
public static void DrawBezier(this Graphics g, Color color, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, bool smooth = true, float penWidth = 1)
|
||||
{
|
||||
using (Pen pen = color.Pen(penWidth))
|
||||
{
|
||||
using Pen pen = color.Pen(penWidth);
|
||||
g.Smooth(smooth);
|
||||
g.DrawBezier(pen, x1, y1, x2, y2, x3, y3, x4, y4);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制贝塞尔曲线
|
||||
@ -454,13 +429,11 @@ namespace Sunny.UI
|
||||
/// <param name="penWidth">笔宽</param>
|
||||
public static void DrawBeziers(this Graphics g, Color color, PointF[] points, bool smooth = true, float penWidth = 1)
|
||||
{
|
||||
using (Pen pen = color.Pen(penWidth))
|
||||
{
|
||||
using Pen pen = color.Pen(penWidth);
|
||||
g.Smooth(smooth);
|
||||
g.DrawBeziers(pen, points);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制贝塞尔曲线
|
||||
@ -472,13 +445,11 @@ namespace Sunny.UI
|
||||
/// <param name="penWidth">笔宽</param>
|
||||
public static void DrawBeziers(this Graphics g, Color color, Point[] points, bool smooth = true, float penWidth = 1)
|
||||
{
|
||||
using (Pen pen = color.Pen(penWidth))
|
||||
{
|
||||
using Pen pen = color.Pen(penWidth);
|
||||
g.Smooth(smooth);
|
||||
g.DrawBeziers(pen, points);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制闭合曲线
|
||||
@ -490,13 +461,11 @@ namespace Sunny.UI
|
||||
/// <param name="penWidth">笔宽</param>
|
||||
public static void DrawClosedCurve(this Graphics g, Color color, Point[] points, bool smooth = true, float penWidth = 1)
|
||||
{
|
||||
using (Pen pen = color.Pen(penWidth))
|
||||
{
|
||||
using Pen pen = color.Pen(penWidth);
|
||||
g.Smooth(smooth);
|
||||
g.DrawClosedCurve(pen, points);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制闭合曲线
|
||||
@ -510,13 +479,11 @@ namespace Sunny.UI
|
||||
/// <param name="penWidth">笔宽</param>
|
||||
public static void DrawClosedCurve(this Graphics g, Color color, Point[] points, float tension, FillMode fillmode, bool smooth = true, float penWidth = 1)
|
||||
{
|
||||
using (Pen pen = color.Pen(penWidth))
|
||||
{
|
||||
using Pen pen = color.Pen(penWidth);
|
||||
g.Smooth(smooth);
|
||||
g.DrawClosedCurve(pen, points, tension, fillmode);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 填充闭合曲线
|
||||
@ -527,13 +494,11 @@ namespace Sunny.UI
|
||||
/// <param name="smooth">平滑</param>
|
||||
public static void FillClosedCurve(this Graphics g, Color color, Point[] points, bool smooth = true)
|
||||
{
|
||||
using (SolidBrush sb = color.Brush())
|
||||
{
|
||||
using SolidBrush sb = color.Brush();
|
||||
g.Smooth(smooth);
|
||||
g.FillClosedCurve(sb, points);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 填充闭合曲线
|
||||
@ -546,13 +511,11 @@ namespace Sunny.UI
|
||||
/// <param name="smooth">平滑</param>
|
||||
public static void FillClosedCurve(this Graphics g, Color color, Point[] points, FillMode fillmode, float tension, bool smooth = true)
|
||||
{
|
||||
using (SolidBrush sb = color.Brush())
|
||||
{
|
||||
using SolidBrush sb = color.Brush();
|
||||
g.Smooth(smooth);
|
||||
g.FillClosedCurve(sb, points, fillmode, tension);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 填充路径
|
||||
@ -563,13 +526,11 @@ namespace Sunny.UI
|
||||
/// <param name="smooth">平滑</param>
|
||||
public static void FillPath(this Graphics g, Color color, GraphicsPath path, bool smooth = true)
|
||||
{
|
||||
using (SolidBrush sb = color.Brush())
|
||||
{
|
||||
using SolidBrush sb = color.Brush();
|
||||
g.Smooth(smooth);
|
||||
g.FillPath(sb, path);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制路径
|
||||
@ -581,13 +542,11 @@ namespace Sunny.UI
|
||||
/// <param name="penWidth">笔宽</param>
|
||||
public static void DrawPath(this Graphics g, Color color, GraphicsPath path, bool smooth = true, float penWidth = 1)
|
||||
{
|
||||
using (Pen pn = color.Pen(penWidth))
|
||||
{
|
||||
using Pen pn = color.Pen(penWidth);
|
||||
g.Smooth(smooth);
|
||||
g.DrawPath(pn, path);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 填充多边形
|
||||
@ -598,13 +557,11 @@ namespace Sunny.UI
|
||||
/// <param name="smooth">平滑</param>
|
||||
public static void FillPolygon(this Graphics g, Color color, PointF[] points, bool smooth = true)
|
||||
{
|
||||
using (SolidBrush sb = color.Brush())
|
||||
{
|
||||
using SolidBrush sb = color.Brush();
|
||||
g.Smooth(smooth);
|
||||
g.FillPolygon(sb, points);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 填充多边形
|
||||
@ -616,13 +573,11 @@ namespace Sunny.UI
|
||||
/// <param name="smooth">平滑</param>
|
||||
public static void FillPolygon(this Graphics g, Color color, PointF[] points, FillMode fillMode, bool smooth = true)
|
||||
{
|
||||
using (SolidBrush sb = color.Brush())
|
||||
{
|
||||
using SolidBrush sb = color.Brush();
|
||||
g.Smooth(smooth);
|
||||
g.FillPolygon(sb, points, fillMode);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 填充多边形
|
||||
@ -633,13 +588,11 @@ namespace Sunny.UI
|
||||
/// <param name="smooth">平滑</param>
|
||||
public static void FillPolygon(this Graphics g, Color color, Point[] points, bool smooth = true)
|
||||
{
|
||||
using (SolidBrush sb = color.Brush())
|
||||
{
|
||||
using SolidBrush sb = color.Brush();
|
||||
g.Smooth(smooth);
|
||||
g.FillPolygon(sb, points);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 填充多边形
|
||||
@ -651,13 +604,11 @@ namespace Sunny.UI
|
||||
/// <param name="smooth">平滑</param>
|
||||
public static void FillPolygon(this Graphics g, Color color, Point[] points, FillMode fillMode, bool smooth = true)
|
||||
{
|
||||
using (SolidBrush sb = color.Brush())
|
||||
{
|
||||
using SolidBrush sb = color.Brush();
|
||||
g.Smooth(smooth);
|
||||
g.FillPolygon(sb, points, fillMode);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制多边形
|
||||
@ -669,13 +620,11 @@ namespace Sunny.UI
|
||||
/// <param name="penWidth">笔宽</param>
|
||||
public static void DrawPolygon(this Graphics g, Color color, PointF[] points, bool smooth = true, float penWidth = 1)
|
||||
{
|
||||
using (Pen pn = color.Pen(penWidth))
|
||||
{
|
||||
using Pen pn = color.Pen(penWidth);
|
||||
g.Smooth(smooth);
|
||||
g.DrawPolygon(pn, points);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制多边形
|
||||
@ -687,13 +636,11 @@ namespace Sunny.UI
|
||||
/// <param name="penWidth">笔宽</param>
|
||||
public static void DrawPolygon(this Graphics g, Color color, Point[] points, bool smooth = true, float penWidth = 1)
|
||||
{
|
||||
using (Pen pn = color.Pen(penWidth))
|
||||
{
|
||||
using Pen pn = color.Pen(penWidth);
|
||||
g.Smooth(smooth);
|
||||
g.DrawPolygon(pn, points);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 填充椭圆
|
||||
@ -704,13 +651,11 @@ namespace Sunny.UI
|
||||
/// <param name="smooth">平滑</param>
|
||||
public static void FillEllipse(this Graphics g, Color color, Rectangle rect, bool smooth = true)
|
||||
{
|
||||
using (SolidBrush sb = color.Brush())
|
||||
{
|
||||
using SolidBrush sb = color.Brush();
|
||||
g.Smooth(smooth);
|
||||
g.FillEllipse(sb, rect);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制椭圆
|
||||
@ -722,13 +667,11 @@ namespace Sunny.UI
|
||||
/// <param name="penWidth">笔宽</param>
|
||||
public static void DrawEllipse(this Graphics g, Color color, Rectangle rect, bool smooth = true, float penWidth = 1)
|
||||
{
|
||||
using (Pen pn = color.Pen(penWidth))
|
||||
{
|
||||
using Pen pn = color.Pen(penWidth);
|
||||
g.Smooth(smooth);
|
||||
g.DrawEllipse(pn, rect);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 填充椭圆
|
||||
@ -739,13 +682,11 @@ namespace Sunny.UI
|
||||
/// <param name="smooth">平滑</param>
|
||||
public static void FillEllipse(this Graphics g, Color color, RectangleF rect, bool smooth = true)
|
||||
{
|
||||
using (SolidBrush sb = color.Brush())
|
||||
{
|
||||
using SolidBrush sb = color.Brush();
|
||||
g.Smooth(smooth);
|
||||
g.FillEllipse(sb, rect);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制椭圆
|
||||
@ -757,13 +698,11 @@ namespace Sunny.UI
|
||||
/// <param name="penWidth">笔宽</param>
|
||||
public static void DrawEllipse(this Graphics g, Color color, RectangleF rect, bool smooth = true, float penWidth = 1)
|
||||
{
|
||||
using (Pen pn = color.Pen(penWidth))
|
||||
{
|
||||
using Pen pn = color.Pen(penWidth);
|
||||
g.Smooth(smooth);
|
||||
g.DrawEllipse(pn, rect);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 填充椭圆
|
||||
@ -828,13 +767,11 @@ namespace Sunny.UI
|
||||
/// <param name="smooth">平滑</param>
|
||||
public static void FillRectangle(this Graphics g, Color color, Rectangle rect, bool smooth = false)
|
||||
{
|
||||
using (SolidBrush sb = color.Brush())
|
||||
{
|
||||
using SolidBrush sb = color.Brush();
|
||||
g.Smooth(smooth);
|
||||
g.FillRectangle(sb, rect);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制矩形
|
||||
@ -846,13 +783,11 @@ namespace Sunny.UI
|
||||
/// <param name="penWidth">笔宽</param>
|
||||
public static void DrawRectangle(this Graphics g, Color color, Rectangle rect, bool smooth = false, float penWidth = 1)
|
||||
{
|
||||
using (Pen pn = color.Pen(penWidth))
|
||||
{
|
||||
using Pen pn = color.Pen(penWidth);
|
||||
g.Smooth(smooth);
|
||||
g.DrawRectangle(pn, rect);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 填充矩形
|
||||
@ -863,13 +798,11 @@ namespace Sunny.UI
|
||||
/// <param name="smooth">平滑</param>
|
||||
public static void FillRectangle(this Graphics g, Color color, RectangleF rect, bool smooth = false)
|
||||
{
|
||||
using (SolidBrush sb = color.Brush())
|
||||
{
|
||||
using SolidBrush sb = color.Brush();
|
||||
g.Smooth(smooth);
|
||||
g.FillRectangle(sb, rect);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制矩形
|
||||
@ -881,13 +814,11 @@ namespace Sunny.UI
|
||||
/// <param name="penWidth">笔宽</param>
|
||||
public static void DrawRectangle(this Graphics g, Color color, RectangleF rect, bool smooth = false, float penWidth = 1)
|
||||
{
|
||||
using (Pen pn = color.Pen(penWidth))
|
||||
{
|
||||
using Pen pn = color.Pen(penWidth);
|
||||
g.Smooth(smooth);
|
||||
g.DrawRectangle(pn, rect.X, rect.Y, rect.Width, rect.Height);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 填充矩形
|
||||
@ -952,13 +883,11 @@ namespace Sunny.UI
|
||||
/// <param name="smooth">平滑</param>
|
||||
public static void FillRectangles(this Graphics g, Color color, Rectangle[] rects, bool smooth = false)
|
||||
{
|
||||
using (SolidBrush sb = color.Brush())
|
||||
{
|
||||
using SolidBrush sb = color.Brush();
|
||||
g.Smooth(smooth);
|
||||
g.FillRectangles(sb, rects);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 填充多个矩形
|
||||
@ -969,13 +898,11 @@ namespace Sunny.UI
|
||||
/// <param name="smooth">平滑</param>
|
||||
public static void FillRectangles(this Graphics g, Color color, RectangleF[] rects, bool smooth = false)
|
||||
{
|
||||
using (SolidBrush sb = color.Brush())
|
||||
{
|
||||
using SolidBrush sb = color.Brush();
|
||||
g.Smooth(smooth);
|
||||
g.FillRectangles(sb, rects);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制图形形状
|
||||
@ -986,13 +913,11 @@ namespace Sunny.UI
|
||||
/// <param name="smooth">平滑</param>
|
||||
public static void FillRegion(this Graphics g, Color color, Region region, bool smooth = false)
|
||||
{
|
||||
using (SolidBrush sb = color.Brush())
|
||||
{
|
||||
using SolidBrush sb = color.Brush();
|
||||
g.Smooth(smooth);
|
||||
g.FillRegion(sb, region);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制多个矩形
|
||||
@ -1004,13 +929,11 @@ namespace Sunny.UI
|
||||
/// <param name="penWidth">笔宽</param>
|
||||
public static void DrawRectangles(this Graphics g, Color color, Rectangle[] rects, bool smooth = false, float penWidth = 1)
|
||||
{
|
||||
using (Pen pn = color.Pen(penWidth))
|
||||
{
|
||||
using Pen pn = color.Pen(penWidth);
|
||||
g.Smooth(smooth);
|
||||
g.DrawRectangles(pn, rects);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制多个矩形
|
||||
@ -1022,13 +945,11 @@ namespace Sunny.UI
|
||||
/// <param name="penWidth">笔宽</param>
|
||||
public static void DrawRectangles(this Graphics g, Color color, RectangleF[] rects, bool smooth = false, float penWidth = 1)
|
||||
{
|
||||
using (Pen pn = color.Pen(penWidth))
|
||||
{
|
||||
using Pen pn = color.Pen(penWidth);
|
||||
g.Smooth(smooth);
|
||||
g.DrawRectangles(pn, rects);
|
||||
g.Smooth(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制圆角矩形
|
||||
@ -1043,11 +964,9 @@ namespace Sunny.UI
|
||||
g.Smooth(smooth);
|
||||
if (cornerRadius > 0)
|
||||
{
|
||||
using (GraphicsPath path = rect.CreateRoundedRectanglePath(cornerRadius))
|
||||
{
|
||||
using GraphicsPath path = rect.CreateRoundedRectanglePath(cornerRadius);
|
||||
g.DrawPath(pen, path);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g.DrawRectangle(pen, rect);
|
||||
@ -1069,11 +988,9 @@ namespace Sunny.UI
|
||||
g.Smooth(smooth);
|
||||
if (cornerRadius > 0)
|
||||
{
|
||||
using (GraphicsPath path = rect.CreateRoundedRectanglePath(cornerRadius))
|
||||
{
|
||||
using GraphicsPath path = rect.CreateRoundedRectanglePath(cornerRadius);
|
||||
g.FillPath(brush, path);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g.FillRectangle(brush, rect);
|
||||
@ -1127,11 +1044,9 @@ namespace Sunny.UI
|
||||
{
|
||||
if (cornerRadius > 0)
|
||||
{
|
||||
using (GraphicsPath path = rect.CreateRoundedRectanglePath(cornerRadius))
|
||||
{
|
||||
using GraphicsPath path = rect.CreateRoundedRectanglePath(cornerRadius);
|
||||
g.DrawPath(color, path, smooth, penWidth);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g.DrawRectangle(color, rect, smooth, penWidth);
|
||||
@ -1150,11 +1065,9 @@ namespace Sunny.UI
|
||||
{
|
||||
if (cornerRadius > 0)
|
||||
{
|
||||
using (GraphicsPath path = rect.CreateRoundedRectanglePath(cornerRadius))
|
||||
{
|
||||
using GraphicsPath path = rect.CreateRoundedRectanglePath(cornerRadius);
|
||||
g.FillPath(color, path, smooth);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g.FillRectangle(color, rect, smooth);
|
||||
@ -1224,9 +1137,8 @@ namespace Sunny.UI
|
||||
}
|
||||
else
|
||||
{
|
||||
GraphicsPath path = g.CreateFanPath(center, d1, d2, startAngle, sweepAngle);
|
||||
using GraphicsPath path = g.CreateFanPath(center, d1, d2, startAngle, sweepAngle);
|
||||
g.DrawPath(color, path, smooth, penWidth);
|
||||
path.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1250,9 +1162,8 @@ namespace Sunny.UI
|
||||
}
|
||||
else
|
||||
{
|
||||
GraphicsPath path = g.CreateFanPath(center, d1, d2, startAngle, sweepAngle);
|
||||
using GraphicsPath path = g.CreateFanPath(center, d1, d2, startAngle, sweepAngle);
|
||||
g.DrawPath(color, path, smooth, penWidth);
|
||||
path.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1275,9 +1186,8 @@ namespace Sunny.UI
|
||||
}
|
||||
else
|
||||
{
|
||||
GraphicsPath path = g.CreateFanPath(center, d1, d2, startAngle, sweepAngle);
|
||||
using GraphicsPath path = g.CreateFanPath(center, d1, d2, startAngle, sweepAngle);
|
||||
g.FillPath(color, path, smooth);
|
||||
path.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1300,9 +1210,8 @@ namespace Sunny.UI
|
||||
}
|
||||
else
|
||||
{
|
||||
GraphicsPath path = g.CreateFanPath(center, d1, d2, startAngle, sweepAngle);
|
||||
using GraphicsPath path = g.CreateFanPath(center, d1, d2, startAngle, sweepAngle);
|
||||
g.FillPath(color, path, smooth);
|
||||
path.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1321,11 +1230,8 @@ namespace Sunny.UI
|
||||
public static void FillPie(this Graphics g, Color color, int x, int y, int width, int height, float startAngle, float sweepAngle, bool smooth = true)
|
||||
{
|
||||
g.Smooth(smooth);
|
||||
using (Brush br = color.Brush())
|
||||
{
|
||||
using Brush br = color.Brush();
|
||||
g.FillPie(br, x, y, width, height, startAngle, sweepAngle);
|
||||
}
|
||||
|
||||
g.Smooth(false);
|
||||
}
|
||||
|
||||
@ -1356,11 +1262,8 @@ namespace Sunny.UI
|
||||
public static void FillPie(this Graphics g, Color color, float x, float y, float width, float height, float startAngle, float sweepAngle, bool smooth = true)
|
||||
{
|
||||
g.Smooth(smooth);
|
||||
using (Brush br = color.Brush())
|
||||
{
|
||||
using Brush br = color.Brush();
|
||||
g.FillPie(br, x, y, width, height, startAngle, sweepAngle);
|
||||
}
|
||||
|
||||
g.Smooth(false);
|
||||
}
|
||||
|
||||
@ -1447,11 +1350,8 @@ namespace Sunny.UI
|
||||
public static void DrawPie(this Graphics g, Color color, float x, float y, float width, float height, float startAngle, float sweepAngle, bool smooth = true, float penWidth = 1)
|
||||
{
|
||||
g.Smooth(smooth);
|
||||
using (Pen pen = color.Pen(penWidth))
|
||||
{
|
||||
using Pen pen = color.Pen(penWidth);
|
||||
g.DrawPie(pen, x, y, width, height, startAngle, sweepAngle);
|
||||
}
|
||||
|
||||
g.Smooth(false);
|
||||
}
|
||||
|
||||
@ -1484,11 +1384,8 @@ namespace Sunny.UI
|
||||
public static void DrawPie(this Graphics g, Color color, int x, int y, int width, int height, float startAngle, float sweepAngle, bool smooth = true, float penWidth = 1)
|
||||
{
|
||||
g.Smooth(smooth);
|
||||
using (Pen pen = color.Pen(penWidth))
|
||||
{
|
||||
using Pen pen = color.Pen(penWidth);
|
||||
g.DrawPie(pen, x, y, width, height, startAngle, sweepAngle);
|
||||
}
|
||||
|
||||
g.Smooth(false);
|
||||
}
|
||||
|
||||
@ -1521,8 +1418,7 @@ namespace Sunny.UI
|
||||
g.DrawImage(img, new Rectangle(rect.X + angleSize, rect.Bottom - angleSize, rect.Width - angleSize * 2, angleSize),
|
||||
new Rectangle(angleSize, img.Height - angleSize, img.Width - angleSize * 2, angleSize), GraphicsUnit.Pixel);
|
||||
//中间
|
||||
g.DrawImage(img,
|
||||
new Rectangle(rect.X + angleSize, rect.Y + angleSize, rect.Width - angleSize * 2, rect.Height - angleSize * 2),
|
||||
g.DrawImage(img, new Rectangle(rect.X + angleSize, rect.Y + angleSize, rect.Width - angleSize * 2, rect.Height - angleSize * 2),
|
||||
new Rectangle(angleSize, angleSize, img.Width - angleSize * 2, img.Height - angleSize * 2), GraphicsUnit.Pixel);
|
||||
}
|
||||
|
||||
@ -1581,8 +1477,7 @@ namespace Sunny.UI
|
||||
{
|
||||
if (str.IsNullOrEmpty()) return;
|
||||
SizeF sf = g.MeasureString(str, font);
|
||||
using (Brush br = color.Brush())
|
||||
{
|
||||
using Brush br = color.Brush();
|
||||
switch (align)
|
||||
{
|
||||
case ContentAlignment.MiddleCenter:
|
||||
@ -1623,7 +1518,6 @@ namespace Sunny.UI
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制字符串
|
||||
@ -1638,11 +1532,8 @@ namespace Sunny.UI
|
||||
public static void DrawString(this Graphics g, string text, Font font, Color color, RectangleF rect, StringFormat format, float angle)
|
||||
{
|
||||
if (text.IsNullOrEmpty()) return;
|
||||
using (Brush br = color.Brush())
|
||||
{
|
||||
using Brush br = color.Brush();
|
||||
g.DrawStringRotateAtCenter(text, font, color, rect.Center(), (int)angle);
|
||||
//g.DrawString(s, font, br, layoutRectangle, format, angle);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -1657,11 +1548,9 @@ namespace Sunny.UI
|
||||
public static void DrawStringRotateAtCenter(this Graphics g, string text, Font font, Color color, PointF centerPoint, float angle)
|
||||
{
|
||||
if (text.IsNullOrEmpty()) return;
|
||||
using (Brush br = color.Brush())
|
||||
{
|
||||
using Brush br = color.Brush();
|
||||
g.DrawStringRotateAtCenter(text, font, br, centerPoint, angle);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 以文字中心点为原点,旋转文字
|
||||
@ -1708,11 +1597,9 @@ namespace Sunny.UI
|
||||
if (text.IsNullOrEmpty()) return;
|
||||
// Save the matrix
|
||||
Matrix mtxSave = g.Transform;
|
||||
|
||||
Matrix mtxRotate = g.Transform;
|
||||
mtxRotate.RotateAt(angle, rotatePoint);
|
||||
g.Transform = mtxRotate;
|
||||
|
||||
g.DrawString(text, font, brush, rotatePoint, format);
|
||||
|
||||
// Reset the matrix
|
||||
@ -1732,11 +1619,9 @@ namespace Sunny.UI
|
||||
public static void DrawString(this Graphics g, string text, Font font, Color color, PointF rotatePoint, StringFormat format, float angle)
|
||||
{
|
||||
if (text.IsNullOrEmpty()) return;
|
||||
using (Brush br = color.Brush())
|
||||
{
|
||||
using Brush br = color.Brush();
|
||||
g.DrawString(text, font, br, rotatePoint, format, angle);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制根据矩形旋转文本
|
||||
|
Loading…
x
Reference in New Issue
Block a user