Zoomed picture box image size.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Zoomed picture box image size.

Threaded View

  1. #1
    Join Date
    Dec 2012
    Posts
    22

    Zoomed picture box image size.

    Hi folks. I have a problem with getting the size of an image within a picture box, I'll try to explain as clearly as possible.

    On a form I have a picture box, the picture box is anchored to all sides of the form and is set to zoom mode. It has to be zoom mode as I need to display very large images shrunk within the diemsions of the form.

    A dialog is used to select a jpg image, which is loaded into a bitmap, the picturebox image property is then set to the bitmap object. I need to do it this way so I can keep an original copy of the image selected in memory.

    The picture box correctly keeps its borders to the edge of the form and shrinks the largest dimension of the displayed image to keep the correct aspect ratio, the picture is displayed perfectly throughout form resizing.

    For the sake of argument, I want to get the percentage location of a mouse click within the picture displayed, where top left is 0,0 and bottom right is 100,100.

    The problem is I can't find a property within the picturebox that returns the actual size of the image displayed. I can either return the location compared to the actual size of the border, or the original image.

    Code:
    ooooooooooooooooooooooooooooooooooooooooooooooo
    o       xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx      o
    o       x                              x      o
    o       x                              x      o
    o       x                              x      o
    o       x                              x      o
    o       x                              x      o
    o       x                              x      o
    o       x                              x      o
    o       xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx      o
    ooooooooooooooooooooooooooooooooooooooooooooooo
    picturebox.width returns the value for the o's.
    picturebox.image.width returns the value of the original image.
    I can't find a way to return the x,y,w,h values for the x's

    Is there a way to do this easily, or am I going to have to calculate the picture height, width and placement on the form manually to get the correct values?

    Any help would be appreciated.

    Cheers.
    Last edited by GremlinSA; July 1st, 2013 at 01:54 AM. Reason: Added Code tags...

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center