after resizing an image...

  • All right, In my app you can resize the view of an image. A pretty
    normal function. However if you resize the view of the NSImage. (The
    image remains it's size, the view is set to say 150% and the image is
    stretched to 150% inside the view.) I use the NSSizeToFit option in
    the scaling for the imageview.
    Now I thought my math was right to reset the selected area so that
    when the cropping took place the right area was selected however my
    math is WAY off as I get completely unpredictable results. This is
    the formula I was using :

    float factor = originalSize.width / currentSize.size.width;

    then to reset the selection:

    selection.size.width /=factor;
    selection.size.height /=factor;
    selection.origin.x /=factor;
    selection.origin.y /=factor;

    I have also tried dividing it by the viewSize setting with the same
    unpredictable results.. So I cant figure out what I'm doing wrong.
  • --As of October 17, 2007 8:02:10 PM -0700, Development is alleged to have
    said:

    > Now I thought my math was right to reset the selected area so that when
    > the cropping took place the right area was selected however my math is
    > WAY off as I get completely unpredictable results. This is the formula I
    > was using :
    >
    > float factor = originalSize.width / currentSize.size.width;
    >
    > then to reset the selection:
    >
    > selection.size.width /=factor;
    > selection.size.height /=factor;
    > selection.origin.x /=factor;
    > selection.origin.y /=factor;

    --As for the rest, it is mine.

    Width and height are total size, but origin isn't.  You'll need two scaling
    factors here, one for the size of the selection and one for it's placement.
    (If the origin actually moves at all.)

    Daniel T. Staal

    ---------------------------------------------------------------
    This email copyright the author.  Unless otherwise noted, you
    are expressly allowed to retransmit, quote, or otherwise use
    the contents for non-commercial purposes.  This copyright will
    expire 5 years after the author's death, or in 30 years,
    whichever is longer, unless such a period is in excess of
    local copyright law.
    ---------------------------------------------------------------
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today