I'm using bitmaps to create custom images in my WinForm. I have a class that represents a truss and want to visualize it. Right now this is my code for drawing the truss:
public void DrawAnsComponent()
{
Pen pen = new Pen(Color.Black);
maxWidth = 0;
maxHeight = 0;
//Getting size of bitmap
foreach (AnsJoint joint in this.AnsToShow.AnsJoints)
{
if (joint.Location.X.Length > maxWidth)
{
maxWidth = (int)joint.Location.X.Length;
}
if (joint.Location.Y.Length > maxHeight)
{
maxHeight = (int)joint.Location.Y.Length;
}
}
maxHeight += 55; maxWidth += 5;
Bitmap bm = new Bitmap(maxWidth, maxHeight); //Creating Bitmap
gr = Graphics.FromImage(bm); //Creating graphic to project onto bitmap
gr.SmoothingMode = SmoothingMode.HighQuality;
foreach (AnsJoint joint in this.AnsToShow.AnsJoints)
{
PointF jointPoint = this.ToCartesian(new PointF((float)joint.Location.X.Length - 4f, (float)joint.Location.Y.Length + 10f), maxHeight);
gr.DrawString(joint.JointID.ToString(), new Font(FontFamily.GenericMonospace, 6f, FontStyle.Regular, GraphicsUnit.Point, 1, false), Brushes.Black, jointPoint);
}
foreach (AnsMember member in this.AnsToShow.AnsMembers) //Drawing each member
{
List<AnsPanel> panels = member.Panels; //Drawing the panels
foreach (AnsPanel pan in panels)
{
pen.Color = Color.Red;
PointF p1 = this.ToCartesian(new PointF((float)pan.I.Location.X.Length, (float)pan.I.Location.Y.Length), maxHeight);
PointF p2 = this.ToCartesian(new PointF((float)pan.J.Location.X.Length, (float)pan.J.Location.Y.Length), maxHeight);
gr.DrawEllipse(pen, p1.X - 2.5f, p1.Y - 2.5f, 5, 5);
gr.DrawEllipse(pen, p2.X - 2.5f, p2.Y - 2.5f, 5, 5);
/*
gr.DrawEllipse(pen, p1.X - 3, p1.Y - 3.3f, 5, 5);
gr.DrawEllipse(pen, p2.X - 3, p2.Y - 3.3f, 5, 5);
pen.Color = Color.Black;
gr.DrawLine(pen, p1, p2);
*/
}
List<AnsLink> links = member.Links; //Drawing the links
foreach (AnsLink link in links)
{
PointF p1 = this.ToCartesian(new PointF((float)link.I.Location.X.Length, (float)link.I.Location.Y.Length), maxHeight);
PointF p2 = this.ToCartesian(new PointF((float)link.J.Location.X.Length, (float)link.J.Location.Y.Length), maxHeight);
gr.FillEllipse(Brushes.Green, p1.X - 1.5f, p1.Y - 1.5f, 3, 3);
gr.FillEllipse(Brushes.Green, p2.X - 1.5f, p2.Y - 1.5f, 3, 3);
gr.DrawLine(pen, p1, p2);
}
}
pictureBox1.Image = bm;
public PointF ToCartesian(PointF p, int maxHeight)
{
return new PointF(p.X, (p.Y - (maxHeight * .8f)) * -1);
}
And here is the result
So it's working perfectly fine except the pixelation makes it look like a very low quality picture. Is there anything I can change about my code to make the image a higher quality?