Getting the scaled size of an image drawn in an NSImageView
Getting the scaled size of an image drawn in an NSImageView
- Subject: Getting the scaled size of an image drawn in an NSImageView
- From: Robert Palmer Jr <email@hidden>
- Date: Thu, 12 Sep 2002 23:44:46 -0400
I have a class that subclasses NSImageView. I have the NSImageView
configured to scale the image proportionally. I need to draw some
lines over the image and want the lines to be specified in original
image coordinates and scale with the image. I also want to be able to
click on the image and translate the MouseEvent's coordinates into
accurate coordinates in the original image coordinates.
The general question is, how do I determine the current scaling factor
at which an NSImage is being drawn in an NSImageView?
I tried the trick found in one of the samples where they create a
category on NSImageCell and call [super imageRectForBounds:bounds] but
this doesn't seem to get what I want. If the original image is much
larger than the view (in both X and Y) then the returned rect is the
view's bounding rect.
I looked in the headers and there is a private member variable in
NSImageCell (I think that's where it was) that is called _scaledImage.
There must be a way to find out the size of the image.
Currently, for the drawing, what I am doing is, in my subclass, I have
implemented drawRect: and when the NSImageView is drawn, I get called
and draw my lines. The problem is that I have to draw in the
coordinate space of the View even though I want the lines specified in
the coordinate space of the actual image size. I need the scaling
factor to do the conversion.
For the drawing the only alternative I could think of was to create
another image the same size as the original image, do the drawing into
it and then composite it onto the image. The NSImageView would then
scale them both. However, this doesn't fix the problem of clicking on
the image and needing to figure out where, in the image they clicked.
Thanks
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.