Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Detecting a pixel on the SDI

Detecting a pixel on the SDI

Scheduled Pinned Locked Moved C / C++ / MFC
c++comgraphicstutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jw81
    wrote on last edited by
    #1

    Hi all, 1) If I drawn a line on SDI client by using MoveTo() and LineTo(). Is there any method to detect which pixel is drawn? I need to get the coordinates of these pixels. 2) Is there any function in MFC that can calculate the distance of a drawn line (or bezier curve) from the starting point to the endpoint? 3) There is a guide in codeproject.com to redraw the drawn lines when the client window is resized/maximized/minimized. I tried and it works however, there are some codes I wrote in OnDraw to draw out the coords/axis of the client. These drawing from OnDraw is covering my META redrawn line. Please advise. THanks a million. ;)

    K 1 Reply Last reply
    0
    • J jw81

      Hi all, 1) If I drawn a line on SDI client by using MoveTo() and LineTo(). Is there any method to detect which pixel is drawn? I need to get the coordinates of these pixels. 2) Is there any function in MFC that can calculate the distance of a drawn line (or bezier curve) from the starting point to the endpoint? 3) There is a guide in codeproject.com to redraw the drawn lines when the client window is resized/maximized/minimized. I tried and it works however, there are some codes I wrote in OnDraw to draw out the coords/axis of the client. These drawing from OnDraw is covering my META redrawn line. Please advise. THanks a million. ;)

      K Offline
      K Offline
      KaRl
      wrote on last edited by
      #2
      1. There's the CDC::GetPixel(), which can give you the color of a pixel knowing its coordinates, But I'm not sure it's what you want. You can still use the good old geometric equations, knowing two points you know the equation of the line, so the coordinates of all the points of the line. 2) Not at my knowledge. The length of a segment is given by the formula length = sqr((endpoint.x - startpoint.x)*(endpoint.x - startpoint.x) + (endpoint.y - startpoint.y)*(endpoint.y - startpoint.y)). Calculating the length of a bezier curve is a little trickier, you may find a good approximation here[^]. 3) Make all your drawings in your OnDraw method, and begin to draw items who are "behind" at first.

      Fold With Us! War is too serious a matter to entrust to military men - Georges Clémenceau (1841-1929)

      J 1 Reply Last reply
      0
      • K KaRl
        1. There's the CDC::GetPixel(), which can give you the color of a pixel knowing its coordinates, But I'm not sure it's what you want. You can still use the good old geometric equations, knowing two points you know the equation of the line, so the coordinates of all the points of the line. 2) Not at my knowledge. The length of a segment is given by the formula length = sqr((endpoint.x - startpoint.x)*(endpoint.x - startpoint.x) + (endpoint.y - startpoint.y)*(endpoint.y - startpoint.y)). Calculating the length of a bezier curve is a little trickier, you may find a good approximation here[^]. 3) Make all your drawings in your OnDraw method, and begin to draw items who are "behind" at first.

        Fold With Us! War is too serious a matter to entrust to military men - Georges Clémenceau (1841-1929)

        J Offline
        J Offline
        jw81
        wrote on last edited by
        #3

        Thanks K(arl), The program I need to write: 1st) User is required to draw a simple curve on the client. 2nd) The algorithm will scan the SDI client screen to find all the drawn coords on row/col basis. You have suggested to use CDC::GetPixel(). 3rd) Once a drawn pixel is found it will perform a 3x3 matrix check to determine the "connectivity" of this pixel. http://img52.exs.cx/img52/2303/3x3matrix.gif[^]If there are other drawn pixels in this 3x3 matrix, the drawn pixel is not an island. 4th) The program will keep scanning in loop to get to the end point of the curve. From there, the program will mark down a point for each specific distance of pixels. http://img40.exs.cx/img40/513/curve.gif[^] That is why I asked is there any function to check distance between endpoint to endpoint of a curve. My problem: 1) Is there a better way than my algorithm? Anyone has a better idea to scan pls reply here. My method is very tedious. THanks. 2) If there is an intersection such as the two curves intersection point. The program will be bugged (I foresee). Thanks a million

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups