• 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
Re: Resizing images
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Resizing images


  • Subject: Re: Resizing images
  • From: Ryan Britton <email@hidden>
  • Date: Wed, 21 Dec 2005 22:07:55 -0800

Take a look at this:
http://developer.apple.com/documentation/Cocoa/Conceptual/DrawImages/ Concepts/ImageSize.html



On Dec 21, 2005, at 8:27 PM, Luke Burton wrote:

Dear cocoa-dev people,

I am new to Cocoa and Objective-C, but am a competent C++ programmer.

I have kicked off an open source project called SimpleViewer iPhoto Export.
It exports photos from iPhoto into a directory, and prepares them into a
nice flash gallery format. You can see some examples (and download source
code and binaries) from my homepage: http://www.hagus.net/taxonomy/ term/14

Now. The reason I'm writing is that my resizing code appears to create
pretty jagged images, which is less than desireable! I'm quite lost as to
how I can improve my resize "algorithm", as I really pieced together this
code using trial and error, and various usenet postings. If someone could
suggest some improvements, I would be most grateful.

// Given source file "source", resize the longest/shortest edge to be "size"
long, and write to "destination".
+(NSString*)resizeFile:(NSString*)source destination:(NSString*) destination
size:(int)size scaleLongest:(BOOL)scaleLongest
{
NSFileManager * fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:source])
return [NSString stringWithFormat:@"Unable to find source file
\"%s\"", [source UTF8String]];

NSImage * myImage = [[NSImage alloc] initWithContentsOfFile:source];
NSRect srcRect = {NSZeroPoint, [myImage size]};

float targetWidth = 0, targetHeight = 0;
// SNIP - chopped out the code that actually calculates these values.

printf("Translating %f/%f to %f/%f\n", srcRect.size.width,
srcRect.size.height, targetWidth, targetHeight);

[myImage lockFocus];
[myImage setScalesWhenResized:TRUE];
[myImage setSize:NSMakeSize(targetWidth, targetHeight)];
[myImage drawAtPoint:NSZeroPoint fromRect:srcRect
operation:NSCompositeCopy fraction:1.0];

NSBitmapImageRep * imageRep = [[NSBitmapImageRep alloc]
initWithData:[myImage TIFFRepresentation]];

NSData * data = [imageRep representationUsingType:NSJPEGFileType
properties:nil];
[data writeToFile:destination atomically:NO];

[myImage unlockFocus];
[imageRep release];
[myImage release];

return nil;
}



--
Luke Burton.

Yes, questions. Morphology, longevity, incept dates.
_______________________________________________
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

_______________________________________________
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
References: 
 >Resizing images (From: Luke Burton <email@hidden>)

  • Prev by Date: Re: Resizing images
  • Next by Date: NSPredicate limitation?
  • Previous by thread: Resizing images
  • Next by thread: RE: Resizing images
  • Index(es):
    • Date
    • Thread