Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6683501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:49:44+00:00 2026-05-26T04:49:44+00:00

I cannot understand the way GDI+ is drawing line on a surface, may be

  • 0

I cannot understand the way GDI+ is drawing line on a surface, may be it has some algorithm to do it.

For ex. lets take a surface 10×10 px.

  Bitmap img = new Bitmap(10, 10);

Now lets draw a line on this surface, with width 5px and top offset 5px.

  using (var g = Graphics.FromImage(img))
     {
        g.Clear(Color.White);
        var pen = new Pen(Color.Brown);
        pen.Width = 5;
        g.DrawLine(pen, 0F, 5F, 10F,  5F);
     }

We will get:

enter image description here

The drawing didn’t begin at pixel #5, it began from pixel #4.
It is obvious, that the start point is calculated separately. But how?

I’ve tried to get a regularity, and got this:

  y = offset + width/2 - 1

where y is real start point y, offset is selected start point y.

But in some cases this doesn’t work. For example, lets take width=6, selected top offset = 0, we will get y=2, and it will be drawn this way:

enter image description here

It must show 6 pixels but it didn’t.

So there must be more general algorythm for selecting the start point, but I really have no idea aboit what it can be.
Any help appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:49:44+00:00Added an answer on May 26, 2026 at 4:49 am

    There is no offset in the line drawing. The co-ordinates you specify in the DrawLine method define the centre of the line. The top pixel is y - width / 2 and the bottom is y - width / 2 + width - 1. That second formula takes into account the fact that width / 2 is rounded down. Also, the top line is y = 0 and the bottom line is y = 9. So, for you first line:

    top = 5 - (5 / 2) = 3
    bottom = 5 - (5 / 2) + 5 - 1 = 7
    

    and the second line:

    top = 2 - (6 / 2) = -1
    bottom = 2 - (6 / 2) + 6 - 1 = 4
    

    The top edge is clipped to the edge of the bitmap so the line width is reduced.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This HTML table is being misinterpreted by some browsers, and I cannot understand why
I cannot understand the Oracle documentation. :-( Does anybody know how to fetch multiple
I cannot understand how this is possible. Please help!! I have an app with
I cannot understand the calculation 66 ⊕ fa = 9c. The sum is clearly
I cannot understand how Bing Community site is implemented. Clicking one of the All
I cannot understand why the code below is giving me this error in firebug
I cannot understand the Java memory usage. I have an application which is executed
I cannot understand why this throws undefined reference to `floor' : double curr_time =
I still cannot understand what does it mean to return an object in a
The question is simple: I cannot understand the Zipper data structure. My question is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.