[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Problem with image size
From: |
Nicolas Roard |
Subject: |
Re: Problem with image size |
Date: |
Wed, 1 Dec 2004 14:10:07 +0000 |
Le 1 déc. 04, à 08:02, Nicolas Sanchez a écrit :
Adam Fedor wrote:
On Nov 30, 2004, at 5:10 AM, Nicolas Sanchez wrote:
Hello,
My problem is very simple, but I have no simple solution.
I load a big image, I resizes it but no memory is freed.
I do this :
NSImage *img = [[NSImage alloc] initWithContentsOfFile:
@"monImage.jpg"];
[img setScalesWhenResized: YES];
[img setSize: NSMakeSize(100, 100)];
Here the memory is not freed, somebody has a solution ?
setSize sets the size of the cached image (the screen
representation), not the size of the original image data. Even then,
setting the size only invalidates the cache - it's possible that some
of the memory for any system resources that have been used stays
around after this happens.
Ok, if I understand, there is no solution within GNUstep framework. I
need to use something like ImageMagick lib...
What do you want to do exactly ? resizing an NSImage and get a bigger
one ? setSize: will only work when you composite the image on screen,
it doesn't touch the original data; but what you can do, is create an
NSImage with the desired size, lock the focus, composite your scaled
NSImage on it,
unlock the focus, and release the first NSImage.
NSSize size = NSMakeSize (100,100);
NSImage* original = [[NSImage alloc] initWithContentsOfFile:
@"monImage.jpg"];
[original setScalesWhenResized: YES];
[original setSize: size];
NSImage* img = [[NSImage alloc] initWithSize: size];
[img lockFocus];
[original compositeToPoint: NSMakePoint (0,0) operation:
NSCompositeSourceOver];
[img unlockFocus];
[original release];
But I don't understand why you want to have the memory freed in you
original code example -- why should it be freed ? you create an object
img using alloc/init, thus with a ref counter of 1 -- it can't be
freed. If you want to free the object, just send it a release
message...
--
Nicolas Roard
"Any sufficiently advanced technology is indistinguishable from magic."
-Arthur C. Clarke