Results 1 to 14 of 14

Thread: Top Edge Coordinates.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2008
    Posts
    204

    Top Edge Coordinates.

    Hi All,
    Can any body please post code for getting the screen coordinates of the top edge of image in picture box.

    Regards,
    Susheelss

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,477

    Re: Top Edge Coordinates.

    Every control has a PointToScreen method. You can pass Point.Empty to it to get the screen coordinates of a control's own Location and you can pass the Location of any of its children to it to get their screen coordinates.

  3. #3
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,125

    Re: Top Edge Coordinates.

    Is your SizeMode of your picturebox such that the top edge of the image isn't necessarily the same as the top edge of your picturebox's client area, e.g. Zoom or Center mode?

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,477

    Re: Top Edge Coordinates.

    Ah, I didn't read the OP carefully enough. I now see that it's the Image location you're interested in, not the control location. Sorry, missed that.

  5. #5
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,125

    Re: Top Edge Coordinates.

    We don't know that for sure at this point, which is why I asked.
    Also, the answer would be different for Zoom mode and Center mode, but I don't really feel like going through the effort if what is really wanted is what you gave.

  6. #6
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    5,685

    Re: Top Edge Coordinates.

    The top edge of an image in a PictureBox is always 0,0 for the top left.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena


    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. -jmcilhinney

  7. #7
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,477

    Re: Top Edge Coordinates.

    Quote Originally Posted by Niya View Post
    The top edge of an image in a PictureBox is always 0,0 for the top left.
    The top-left of the PictureBox is always at (0,0) with respect to the PictureBox but the top-left of the Image in the PictureBox may be at different places depending on the SizeMode of the control and the Size of both the control and the Image. PointToScreen is still relevant to determining coordinates with respect to the screen, once you have coordinates with respect to the PictureBox.

  8. #8
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,125

    Re: Top Edge Coordinates.

    Quote Originally Posted by Niya View Post
    The top edge of an image in a PictureBox is always 0,0 for the top left.
    I guess perhaps it depends on your definition of image.
    If the bitmaps dimensions are smaller than the size of the picturebox, and the Sizemode is Center, then you will have even gaps (within a pixel) at the top and bottom, and left and right of where the image shows in the picturebox, so the top edge of the "image" would be at (Picturebox.ClientSize.Height - Bitmap.Height) \ 2, give or take a pixel.
    If the image is larger vertically than the picturebox, with Sizemode of Center, the top edge of the image might be outside the bounds of the picturebox, I don't know, which is why I said I would have to do some work to provide an answer.

    Likewise, if the SizeMode is set to Zoom, then the image will be sized proportionally to completely fit within the picturebox, so if the bitmap height to width ratio is less than the pictureboxes height to width ratio then the image will fill the picturebox horizontally, but center vertically so you will again have a gap at the top and bottom of the picturebox.

  9. #9
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    5,685

    Re: Top Edge Coordinates.

    Quote Originally Posted by jmcilhinney View Post
    The top-left of the PictureBox is always at (0,0) with respect to the PictureBox but the top-left of the Image in the PictureBox may be at different places depending on the SizeMode of the control and the Size of both the control and the Image. PointToScreen is still relevant to determining coordinates with respect to the screen, once you have coordinates with respect to the PictureBox.
    Quote Originally Posted by passel View Post
    I guess perhaps it depends on your definition of image.
    If the bitmaps dimensions are smaller than the size of the picturebox, and the Sizemode is Center, then you will have even gaps (within a pixel) at the top and bottom, and left and right of where the image shows in the picturebox, so the top edge of the "image" would be at (Picturebox.ClientSize.Height - Bitmap.Height) \ 2, give or take a pixel.
    If the image is larger vertically than the picturebox, with Sizemode of Center, the top edge of the image might be outside the bounds of the picturebox, I don't know, which is why I said I would have to do some work to provide an answer.

    Likewise, if the SizeMode is set to Zoom, then the image will be sized proportionally to completely fit within the picturebox, so if the bitmap height to width ratio is less than the pictureboxes height to width ratio then the image will fill the picturebox horizontally, but center vertically so you will again have a gap at the top and bottom of the picturebox.
    Hmmmm, I see. I've always used PictureBoxes with the SizeMode set to Stretch. I never actually tested what would happen with other SizeModes. Good to know.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena


    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. -jmcilhinney

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Aug 2008
    Posts
    204

    Re: Top Edge Coordinates.

    Hi all,
    Thanks for the replies. The actual need is like this:

    I have a picture box whose sizemode is set to Center. Now based on user zooming and panning the image inside the picturebox, I need to get only the pixel data of image only displayed inside picturebox. I have written code to get the data from original image, if the top-Left pixel coordinate and bottom-right pixel coordinate of the image inside picturebox is known.

    Now I need to find the top-left pixel coordinate and bottom-right pixel coordinate. Offcourse if the image is zoomed beyond size of picture box, then top-left coordinate is (0,0). But what if image is Zoomed in???

    Thanks and Regards,
    Susheelss

  11. #11
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,125

    Re: Top Edge Coordinates.

    If you have the sizemode set to Center, how is the user zooming and panning the image?
    In order to zoom and pan the image, the image has to be drawn in the picturebox, not an image contained in the picturebox, unless the zooming and panning is changing the image loaded in the picturebox.

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Aug 2008
    Posts
    204

    Re: Top Edge Coordinates.

    Sorry my mistake. Actually image is drawn in the picturebox.



    Quote Originally Posted by passel View Post
    If you have the sizemode set to Center, how is the user zooming and panning the image?
    In order to zoom and pan the image, the image has to be drawn in the picturebox, not an image contained in the picturebox, unless the zooming and panning is changing the image loaded in the picturebox.

  13. #13
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,125

    Re: Top Edge Coordinates.

    So, now you have the issue of who is in control of the panning and zooming.
    To implement panning and zooming the code could be putting a portion of the original picture (using a source rectangle) to a portion of the picturebox (using a destination rectangle), (zooming being done by having different size source and destination rectangles).
    If that is the case, then the area of the picturebox drawn to would be defined by the destination rectangle. There is no way you could know what it was after the fact, you would have to capture that information in the pan and zoom code.

    Likewise, they may not be using source and destination rectangles at all, but using matrix transforms, to scale and translate the image.
    Again, you wouldn't be able to detect what area was drawn, you would have to know the scale and translation values used in the pan and zoom code.

    There may be other methods to do pan and zoom, like using a picturebox in zoom mode being moved inside of a panel or other control and just changing the size and position of the picturebox within its container.

    If you don't have access to the pan and zooming code and can have it capture the needed data, I think you are asking the nearly impossible.

  14. #14
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,477

    Re: Top Edge Coordinates.

    Quote Originally Posted by Susheelss View Post
    Sorry my mistake. Actually image is drawn in the picturebox.
    For future reference, don't wait until post #12 to actually explain the problem fully.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width