c# - Drawline with same pen width, but the line widths are different in result -


I draw a line with the same pen, but why is the line width of the result different?

  Bitmap B = new bitmap (400, 400); Graphics G = Graphics. Framesize (b); G.PageUnit = GraphicsUnit.Point; G.Clear (Color.White); Pen pen = new pen (color. Red, 1.2f); G.Dispose (); B.Save ("I" D: /temp/test.png ", ImageFormat.Png); B.Dispose ()  

Here is the result:

< P>

That's because you are working with numbers and not pixels and the difference in the width of the lines is the result of a round errors in the line place and how to provide it in pixels in the final productE is the width of the line in relation to it.

If you do not care about printing the image, it is best to stick to the pixel.

Edit : If you want to continue using the points, / P>

  Bitmap B = new bitmap (400, 400); Graphics G = Graphics. Framesize (b); G.PageUnit = GraphicsUnit.Point; G.Clear (Color.White); pen pen = new pen (color. Red, 1.2f); for (float i = 20f * pen. Wide; I & lt; 200f * pen. Wide; I = i + 20F * pen. Wide) {g.DrawLine (pen, 10f, i, 190f, i); } G.Dispose (); B Save ("c: /temp/test.png", ImageFormat.Png); B.Dispose ();  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -