.NET WinForms图像艺术像素化代码问题求助
.NET WinForms图像艺术像素化效果不符合预期,求代码审查
我在.NET WinForms中编写了生成输入图像艺术像素化效果的代码,但无法得到预期结果,预期效果与当前生成效果均已附图。以下是我的DrawShape方法代码:
private void DrawShape(Graphics g, Brush brush, int x, int y, int size) { int halfSize = size / 2; int xOffset = chkOverlap.Checked ? -halfSize : 0; int yOffset = chkOverlap.Checked ? -halfSize : 0; if (chkCircle.Checked) { // Draw the outer circle g.FillEllipse(brush, x + xOffset, y + yOffset, size, size); // Draw the first inner circle (blue color) using (Brush innerBrush1 = new SolidBrush(Color.Blue)) { int innerSize1 = size / 2; int innerX1 = x + halfSize - innerSize1 / 2 + xOffset; int innerY1 = y + halfSize - innerSize1 / 2 + yOffset; g.FillEllipse(innerBrush1, innerX1, innerY1, innerSize1, innerSize1); } // Draw the second inner circle (red color) using (Brush innerBrush2 = new SolidBrush(Color.Red)) { int innerSize2 = size / 3; int innerX2 = x + halfSize - innerSize2 / 2 + xOffset; int innerY2 = y + halfSize - innerSize2 / 2 + yOffset; g.FillEllipse(innerBrush2, innerX2, innerY2, innerSize2, innerSize2); } } else if (chkSquare.Checked) { g.FillRectangle(brush, x + xOffset, y + yOffset, size, size); } else if (chkTriangle.Checked) { PointF[] trianglePoints = new PointF[] { new PointF(x + size / 2 + xOffset, y + yOffset), new PointF(x + xOffset, y + size + yOffset), new PointF(x + size + xOffset, y + size + yOffset) }; g.FillPolygon(brush, trianglePoints); } else if (chkRectangle.Checked) { g.FillRectangle(brush, x + xOffset, y + yOffset, size * 2, size); } }
我尝试过上述代码,但生成效果不符合预期,恳请协助解决。
内容的提问来源于stack exchange,提问作者vampire
相关产品推荐
相关产品推荐

