Re: NSImage buggy when scaling images above real size?
Re: NSImage buggy when scaling images above real size?
- Subject: Re: NSImage buggy when scaling images above real size?
- From: "Louis C. Sacha" <email@hidden>
- Date: Tue, 16 Mar 2004 23:21:42 -0800
Hello...
I don't know what is causing your current problem, but perhaps you
could avoid actually changing the size of the images by using a
different method to composite? For example, something like this,
using drawInRect:fromRect:operation:fraction: instead of one of the
compositeToPoint... methods:
/* typed in mail, this doesn't really need to be a seperate method, etc... */
- (void)drawScaledImage:(NSImage)yourImage
withSize:(NSSize)scaledSize atPoint:(NSPoint)location
{
NSRect sourceRect, displayRect;
sourceRect.origin.x = sourceRect.origin.y = 0.0f;
sourceRect.size = [yourImage size];
displayRect.origin = location;
displayRect.size = scaledSize;
[yourImage drawInRect:displayRect fromRect:sourceRect
operation:NSCompositeSourceOver fraction:1.0f];
}
That way you never have to change the cached size of the images, and
instead you can just calculate the scaled NSSize as needed or store
it somehow if you prefer.
Hope that helps,
Louis
I'm working with groups of NSImages in a view similar to iPhoto's
(or any such thing), where the images can be viewed at various
scales as controlled by a continuous scroller. This works pretty
well when the scale is equal to or smaller than the real image sizes
- performance isn't quite as good as iPhoto, but it's good enough.
Some playing with caching should improve this, I imagine.
The problem occurs when the scale is set larger than the image
sizes. For example, in my current test case I have 6 400x400
images. If I set the scale such that they need to be drawn at
401x401 [for example], then somewhere between [and including]
setSize: and compositeToPoint: my app locks up completely. It just
starts sucking up memory as fast as it physically can, which on my
little iBook is as fast as the hard drive can handle (given that OS
+ XCode in debug mode uses nearly all of the 256 meg physical memory
:( ).
I've tried all 4 caching modes (default through never), and while
BySize is by far the worst (pretty much requires a hard restart),
they all exhibit the problem. No image ever actually makes it to
the screen. I have left my app running for up to 10 minutes to see
if it's just incredibly slow, but it doesn't seem so - memory usage
increases linearly the whole time, to the point where it reaches
more than a gigabyte, for images who's on disk size is less than a
meg each (as pict's).
Debugging this is compounded by the fact that I can't - this
thrashing locks up my iBook almost completely. The best I can
manage is to throw a few mouse clicks at XCode's Terminate button
and go for coffee, so to speak. It takes about 3 minutes on average
just to change to XCode and trigger that kill. It would be nice if
XCode had an option to manipulate the environment limits of the apps
it launches.
Is there any reason scaling an image above it's real size would
exhibit this behaviour, and more importantly how can I make it not?
I'll probably alter my code in the meantime to avoid scaling above
real size, but sooner or later I'm going to have to be able to zoom
in on an image... :/
Wade Tregaskis
-- Sed quis custodiet ipsos custodes?
_______________________________________________
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.