Skip to content

Commit d05725e

Browse files
committed
图像绘制方式可选择像素化或者平滑
1 parent 0ade525 commit d05725e

File tree

14 files changed

+93
-32
lines changed

14 files changed

+93
-32
lines changed

DrawKit/CanvasForm.Designer.cs

Lines changed: 54 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DrawKit/CanvasForm.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ private void InitializeCanvas()
8585
g.Clear(_canvasBackgroundColor); // 初始化背景色
8686
g.SmoothingMode = SmoothingMode.HighQuality; //高质量
8787
g.PixelOffsetMode = PixelOffsetMode.HighQuality; //高像素偏移质量
88+
8889
}
8990
// 启用双缓冲
9091
typeof(Panel).InvokeMember(
@@ -126,6 +127,7 @@ private void LoadInstalledFonts()
126127

127128
private void CanvasForm_Load(object sender, EventArgs e)
128129
{
130+
cmb_SmoothMode.SelectedIndex = 0;
129131
cmb_size.SelectedIndex = 0;
130132
cmb_TextSize.SelectedIndex = 0;
131133
cmb_FontFamily.SelectedIndex = 0;
@@ -1199,7 +1201,7 @@ private void PerformValidation(ComboBox comboBox)
11991201
}
12001202
else
12011203
{
1202-
comboBox.Text = string.IsNullOrEmpty(_cmbScaleLastText) ? "100":_cmbScaleLastText;
1204+
comboBox.Text = string.IsNullOrEmpty(_cmbScaleLastText) ? "100" : _cmbScaleLastText;
12031205
}
12041206
}
12051207

@@ -1231,5 +1233,14 @@ private void rtb_Text_KeyDown(object sender, KeyEventArgs e)
12311233
}
12321234
}
12331235
}
1236+
1237+
private void cmb_SmoothMode_SelectedIndexChanged(object sender, EventArgs e)
1238+
{
1239+
_shape.EnableAntiAlias = cmb_SmoothMode.SelectedIndex == 0 ? false : true;
1240+
_shape.drawStatus = DrawStatus.AdjustTheStyle;
1241+
if (_shape is RectangularSelection) return;
1242+
panel_main.Refresh();
1243+
panel_main.Refresh();
1244+
}
12341245
}
12351246
}

DrawKit/Shapes/Circle.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ private void DrawCreating(Graphics graphics)
216216
{
217217
using (Pen selectionPen = new Pen(ForeColor, Size))
218218
{
219+
if(EnableAntiAlias) g.SmoothingMode = SmoothingMode.AntiAlias;
219220
g.DrawEllipse(selectionPen, ConvertSelectionRectToCanvasRect(SelectionRect));
220221
}
221222
}
@@ -228,6 +229,7 @@ private void DrawCanMoveOrAdjusted(Graphics graphics)
228229
{
229230
using (Pen selectionPen = new Pen(ForeColor, Size))
230231
{
232+
if (EnableAntiAlias) g.SmoothingMode = SmoothingMode.AntiAlias;
231233
g.DrawEllipse(selectionPen, ConvertSelectionRectToCanvasRect(SelectionRect));
232234
}
233235
}

DrawKit/Shapes/Hexagon.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ private void DrawCreating(Graphics graphics)
253253
{
254254
using (Pen selectionPen = new Pen(ForeColor, Size))
255255
{
256+
if (EnableAntiAlias) g.SmoothingMode = SmoothingMode.AntiAlias;
256257
g.DrawPolygon(selectionPen, ConvertVertexs(_vertexs));
257258
}
258259
}
@@ -265,6 +266,7 @@ private void DrawCanMoveOrAdjusted(Graphics graphics)
265266
{
266267
using (Pen selectionPen = new Pen(ForeColor, Size))
267268
{
269+
if (EnableAntiAlias) g.SmoothingMode = SmoothingMode.AntiAlias;
268270
g.DrawPolygon(selectionPen, ConvertVertexs(_vertexs));
269271
}
270272
}

DrawKit/Shapes/Line.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ private void DrawCreating(Graphics graphics)
257257
{
258258
using (Pen pen = new Pen(ForeColor, Size))
259259
{
260+
if (EnableAntiAlias) g.SmoothingMode = SmoothingMode.AntiAlias;
260261
g.DrawLine(pen, ConvertPoint(StartPoint), ConvertPoint(EndPoint));
261262
}
262263
}
@@ -269,6 +270,7 @@ private void DrawMoveOrAdjusted(Graphics graphics)
269270
{
270271
using (Pen pen = new Pen(ForeColor, Size))
271272
{
273+
if (EnableAntiAlias) g.SmoothingMode = SmoothingMode.AntiAlias;
272274
g.DrawLine(pen, ConvertPoint(StartPoint), ConvertPoint(EndPoint));
273275
}
274276
}

DrawKit/Shapes/Pencil.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ private void DrawPath(Point start, Point end)
104104

105105
if (distance < 1)
106106
{
107+
if (EnableAntiAlias) g.SmoothingMode = SmoothingMode.AntiAlias;
107108
g.FillRectangle(new SolidBrush(ForeColor),
108109
start.X - eraserSize / 2,
109110
start.Y - eraserSize / 2,
@@ -116,7 +117,7 @@ private void DrawPath(Point start, Point end)
116117
{
117118
int x = (int)(start.X + t * (end.X - start.X));
118119
int y = (int)(start.Y + t * (end.Y - start.Y));
119-
120+
if (EnableAntiAlias) g.SmoothingMode = SmoothingMode.AntiAlias;
120121
g.FillRectangle(new SolidBrush(ForeColor),
121122
x - eraserSize / 2,
122123
y - eraserSize / 2,

DrawKit/Shapes/Pentagon.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ private void DrawCreating(Graphics graphics)
255255
{
256256
using (Pen selectionPen = new Pen(ForeColor, Size))
257257
{
258+
if (EnableAntiAlias) g.SmoothingMode = SmoothingMode.AntiAlias;
258259
g.DrawPolygon(selectionPen, ConvertVertexs(_vertexs));
259260
}
260261
}
@@ -267,6 +268,7 @@ private void DrawCanMoveOrAdjusted(Graphics graphics)
267268
{
268269
using (Pen selectionPen = new Pen(ForeColor, Size))
269270
{
271+
if (EnableAntiAlias) g.SmoothingMode = SmoothingMode.AntiAlias;
270272
g.DrawPolygon(selectionPen, ConvertVertexs(_vertexs));
271273
}
272274
}

DrawKit/Shapes/Rhombus.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ private void DrawCreating(Graphics graphics)
244244
{
245245
using (Pen selectionPen = new Pen(ForeColor, Size))
246246
{
247+
if (EnableAntiAlias) g.SmoothingMode = SmoothingMode.AntiAlias;
247248
g.DrawPolygon(selectionPen, ConvertVertexs(_vertexs));
248249
}
249250
}
@@ -255,6 +256,7 @@ private void DrawCanMoveOrAdjusted(Graphics graphics)
255256
{
256257
using (Pen selectionPen = new Pen(ForeColor, Size))
257258
{
259+
if (EnableAntiAlias) g.SmoothingMode = SmoothingMode.AntiAlias;
258260
g.DrawPolygon(selectionPen, ConvertVertexs(_vertexs));
259261
}
260262
}

DrawKit/Shapes/RightTriangle.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ private void DrawCreating(Graphics graphics)
240240
{
241241
using (Pen selectionPen = new Pen(ForeColor, Size))
242242
{
243+
if (EnableAntiAlias) g.SmoothingMode = SmoothingMode.AntiAlias;
243244
g.DrawPolygon(selectionPen, ConvertVertexs(_vertexs));
244245
}
245246
}
@@ -251,6 +252,7 @@ private void DrawCanMoveOrAdjusted(Graphics graphics)
251252
{
252253
using (Pen selectionPen = new Pen(ForeColor, Size))
253254
{
255+
if (EnableAntiAlias) g.SmoothingMode = SmoothingMode.AntiAlias;
254256
g.DrawPolygon(selectionPen, ConvertVertexs(_vertexs));
255257
}
256258
}

DrawKit/Shapes/RoundedRectangle.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ private void DrawCreating(Graphics graphics)
251251
{
252252
using (Pen selectionPen = new Pen(ForeColor, Size))
253253
{
254+
if (EnableAntiAlias) g.SmoothingMode = SmoothingMode.AntiAlias;
254255
g.DrawPath(selectionPen, _pathInBitmap);
255256
}
256257
}
@@ -262,6 +263,7 @@ private void DrawCanMoveOrAdjusted(Graphics graphics)
262263
{
263264
using (Pen selectionPen = new Pen(ForeColor, Size))
264265
{
266+
if (EnableAntiAlias) g.SmoothingMode = SmoothingMode.AntiAlias;
265267
g.DrawPath(selectionPen, _pathInBitmap);
266268
}
267269
}

0 commit comments

Comments
 (0)