Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image Zoom-In Zoom-Out in NSImageView

Tags:

cocoa

zooming

Can anyone please suggest me a good sample code for zooming image in NSImageView. Thanks.

like image 812
Ganesh Nayak Avatar asked Jul 02 '09 06:07

Ganesh Nayak


2 Answers

If you look at the documentation, you'll see that NSImageView doesn't support this. Use Image Kit instead.

like image 125
Peter Hosey Avatar answered Oct 18 '22 07:10

Peter Hosey


While technically NSImageView doesn't technically support this, it is possible. I believe by changing the bounds of the NSView that you're using, and make sure that the image is set to "Proportionally Down", or "Proportionally Up or Down".

This code seems to work for me, on OSX 10.9 (Mavericks)

   NSSize size = [_imageView bounds].size;

   NSSize newSize = NSMakeSize(size.width * 0.90, size.height * 0.90);

   [_imageView setBoundsSize: newSize];

I have also had success "embedding" an image view inside a scroll view, and then using magnification on the scroll view. YMMV

like image 36
rnovak1988 Avatar answered Oct 18 '22 07:10

rnovak1988