• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Resampling/resizing pictures (solved but why ?)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: NSData questions (including Altivec)
  • Next by Date: Re: NSAppKitVersionNumber for 10.3.0?
  • Previous by thread: Re: NSData questions (including Altivec)
  • Next by thread: initWithPasteboard: which representation
  • Index(es):
    • Date
    • Thread