Resampling/resizing pictures (solved but why ?)
Resampling/resizing pictures (solved but why ?)
- Subject: Resampling/resizing pictures (solved but why ?)
- From: Yann Bizeul <email@hidden>
- Date: Mon, 20 Sep 2004 11:48:46 +0200
Hi list,
I'm working on a client/server application, one of the server tasks is
to take a TIFF file, then resample it to says, 200x200 pixels at 72
dpi.
What I was doing is :
- Put the full size TIFF file in a NSImage
- Allocate an NSImage fwith the thumbnail size
- Lock focus on it
- Use NSImage's drawInRect:fromRect:operation:fraction: to draw in the
thumbnail.
With this method, if the source image is 300dpi, I get a ugly
thumbnail with big pixels.
So I searched a bit in the archives, and found this thread :
http://cocoa.mamasam.com/MACOSXDEV/2001/10/2/15145.php
This method works perfectly, but why ? I don't understand why working
with the NSBitmapImageRep directly does produce a better result.
Here is the working code :
- (NSBitmapImageRep *)representationWithSize:(NSSize)size
{
NSRect rect = NSMakeRect(0, 0, size.width, size.height);
NSImage *image = [[[NSImage alloc] initWithSize:size] autorelease];
NSBitmapImageRep *outRep;
[image lockFocus];
[[NSGraphicsContext
currentContext]setImageInterpolation:NSImageInterpolationHigh];
[self drawInRect:rect];
outRep = [[[NSBitmapImageRep alloc] initWithFocusedViewRect:rect]
autorelease];
[image unlockFocus];
return outRep;
}
--
Yann Bizeul - yann at tynsoe.org
Cocoa Developer, visit my projects at :
http://projects.tynsoe.org/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden