PDA

View Full Version : Rotate a NSView and make it's origin point starts from the bottom left corner




smokyonion
May 24, 2011, 10:19 AM
Hi,

I have a NSImageView subclass which is responsible for drawing image data grabbed from the live view of a digital camera.

The NSImageView subclass is also nested inside another NSView (the parent view) or a NSWindow's content view.

Meanwhile, the NSImageView subclass draw grids and a crop marker rectangle so the user can do a pre-crop of the image that are going to be taken and downloaded from the camera.

My first question is how can I keep my NSImageView centered if I rotate the NSImageView 90 degrees.

For example, I use setFrameCenterRotation:(NSRect)

However, this approach has a problem in which, when the window or the parent view is resized, the NSImageView's position will not be centered anymore.

http://d.pr/vbGG

http://d.pr/T3QC

My 2nd question is how can I maintain the NSImageView's frame to always conform to its image size and aspect ratio; also, the grid fits the image completely.

My 3rd question is what if my NSImage in NSImageView is larger in width and when rotated it exceeds the size limit in the parentview, how can I maintain the aspect ratio of the original image in NSImageView.

My 4th question is when I resize the parentview, is it possible for the NSImageView to simultaneously resize with the parentview when I resize the parentview. Also, will both the NSImageView and parentview maintain aspect ratios.

My 5th question is how can I maintain the original intersecting points, even when the image is rotated 90 degrees.

As you may know, if the camera is rotated by the photographer, then the captured image will contain orientation EXIF info. On 10.6 the NSImage init methods have been added support for handling EXIF orientation info. The NSRect of crop marker will not be corrected if I cannot maintain the original intersecting points.

My 6th question is there any recommended books I should read to help solve the problems above and possible ones in the future.

Your help and reply will be really appreciated.

Sincerely.



kainjow
May 25, 2011, 09:59 AM
If I were you, I would not use NSImageView for this. To me it seems like it'll just get in the way.

I would just do a custom NSView that draws the image directly with everything else. This way you can control rotation directly through NSAffineTransform, instead of relying on Core Animation.

For maintaining aspect ratio, see rescaleRect:toFitInSize: (http://www.cocoadev.com/index.pl?ThumbnailImages)

Sydde
May 25, 2011, 01:33 PM
Take a look at the documentation for NSWindow, there is a way described in there to maintain the aspect ratio of your window as the user resizes it.