i have written this code to draw an artistic pixilation of inputed image. but i am unable to get the result which i want. can someone help me by reviewing my code. i am using window forms .net.
Desired ouput has been shown in this picture
my code is this :
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);
}
}
code is generating this image. but i want the result like i have shown in above photo.
tried this
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);
}
}

