Re: [newbie] translating mouse location in an NSImageView
Re: [newbie] translating mouse location in an NSImageView
- Subject: Re: [newbie] translating mouse location in an NSImageView
- From: Marco Binder <email@hidden>
- Date: Thu, 19 Sep 2002 20:22:56 +0200
First, get the origin of your displayed image. In your example, that
would be (80,0) since 640-480 = 160, that is 80 pixels on both sides.
Subtract that from your view-coord related mouse-click (say it was at
(200,200), now set it to (120,200)). Now get the NSBitmapImageRep of
your image (NSBitmapImageRep initWith
Data:[NSImage TIFFRepresenation]).
This ImageRep has two instance-variables: pixelsWide and pixelsHigh.
With these and a simple rule of three, you can get the x and y
coordinates in your original image.
Note however: The image can be of a different resolution than 72 dpi.
That's the difference between [NSBitmapImageRep size] and
[NSBitmapImageRep pixelsWide] / [NSBitmapImageRep pixelsHigh]. you have
to know, to which image size you want to convert the point!
marco
Am Donnerstag, 19.09.02 um 14:42 Uhr schrieb Robert Palmer Jr:
sorry for the cross-post and re-post - I'm in desperate need of a
solution and have not yet figured this out. NSImageView seems so
simple, but I can't get past this problem.
I have a class that subclasses NSImageView. I have the NSImageView
configured to scale the image proportionally. I want to be able to
click on the scaled image view and determine where in the original
image that click occurred. This means I need to translate the
MouseEvent's coordinates into accurate coordinates in the original
image coordinate space.
The question is, how do I determine the current scaling factor at
which an NSImage is being drawn in an NSImageView?
Here's the basic process (I know the function names aren't correct - I
don't have my code in front of me and don't remember the exact names)
I have the first two steps working fine, just need the last step:
Assume I have a 1024x1024 image being displayed proportionally in a
640x480 view (which means it will actually be displayed at 480x480).
mouseClick --> get coordinates in window space
convertToViewCoor --> get coordinates of click in view space (in
640x480 range)
WHAT_GOES_HERE --> get cooridnates of click in original image space
(in 1024x1024 range)
Robert Palmer, Jr
email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
--
|\ /| E-Mail: email@hidden WWW: www.marco-binder.de
| \/ | Telefon: 07531 / 94 19 94 Fax: 07531 / 94 19 92
| |ARCO Snail-Mail: Banater Str. 3 - 78467 Konstanz
BINDER _____________________________________________________
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.