Making an image "zoom"
Making an image "zoom"
- Subject: Making an image "zoom"
- From: Josh Anon <email@hidden>
- Date: Sat, 2 Feb 2002 14:23:48 -0600
Hi,
I've got an image loaded into an NSImageView, and it's inside a
NSScrollView. What I'm working on now is a way to zoom in/out of the
image. It's mostly working, but I've encountered a few weird things I
can't figure out, and I was wondering if anyone else has seen them.
Here's the algorithm so far:
to zoom:
new image size = [[imageView image] size] * factor
new image view bounds = [imageView bounds]
new image view bounds size = new image size
[imageView setFrameSize:new image size]
[imageVew setBounds:new image view bounds]
//scrSz = width/height of scroll bar
if (new image size + scrSz < current window size)
set the window's frame's size to new image size + scrSz
set the new frame and display the window
max window size = new image size + scrSz
[imageView setNeedsDisplay];
and to make sure the image stays at the top left, I implemented
windowWillResize:toSize:
[[scrollView contentView] setBounds:bounds w/ correct origin and size ==
image size]
if (suggested new size > image size)
new size = image size
return new size
Now, when I run the code, the image first loads/scrolls correctly. If I
zoom in/out and the image stays bigger than the image, it works fine.
However, if I zoom out until the window is bigger than the image, weird
things happen--the image is displayed in a space about 10px x 40px on
the bottom left. If I zoom in once, it works fine. Resizing is the
weirder problem, though. When I resize, the scroll bars sometimes just
go away, even if there is more image than is displayed. Also, when I
resize the window, the vertical limit works ok, but the horizontal limit
has problems--I can resize the window past the size of the image. Other
times, Cocoa won't redraw the entire image view, even if it's completely
in the window, and part of the right side will be cut off.
So, I'm sure there's something obvious I'm missing, but I don't see it.
Any ideas?
Thanks,
Josh
--
//email@hidden ||
http://www.areax.net
"Ford, you're turning into a penguin. Stop it." -- Douglas Adams,
Hitchhiker's Guide to the Galaxy