Friday, October 22, 2010

Learn from Real Codes (iPhone Pictures)

A Real Example: (Can you guess it?)

NSImage *image = [[NSImage alloc] initWithContentsOfFile:path];
[image setScalesWhenResized:YES];
[image setSize:NSMakeSize(1000.0, [image size].height * (1000.0/[image size].width))];
//set to high qualify
[[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
//Tune ant...
[[NSGraphicsContext currentContext] setShouldAntialias:YES];
NSImage *canvas = [[NSImage alloc] initWithSize:canvasSize];
[canvas lockFocus];

//Draw things here.

[canvas unlockFocus];
int border = 56;

NSRect rect = NSMakeRect(border/2, border/2, canvasSize.width - border, canvasSize.height - border);
[originImage drawInRect:rect
 fromRect:NSZeroRect
 operation:NSCompositeSourceOver
 fraction:1.0];

border -= 6;
[[NSColor whiteColor] set];
NSRect whiteBorderRect = NSMakeRect(border/2, border/2,
 canvasSize.width - border, canvasSize.height - border);
NSBezierPath *whiteBorder = [NSBezierPath bezierPathWithRect:whiteBorderRect];
[whiteBorder setLineJoinStyle:NSRoundLineJoinStyle];
[whiteBorder setLineWidth:2];
[whiteBorder stroke];
NSData *imageData = [NSData dataWithContentsOfFile:imagePath];
CGImageSourceRef source = CGImageSourceCreateWithData((CFDataRef)imageData, NULL);

NSDictionary *metaData = (NSDictionary *)CGImageSourceCopyPropertiesAtIndex(source,0,NULL);
NSDictionary *exifData = [metaData objectForKey:@"{Exif}"];
NSDictionary *tiffData = [metaData objectForKey:@"{TIFF}"];

NSData *imageData = [NSData dataWithContentsOfFile:imagePath];
CGImageSourceRef source = CGImageSourceCreateWithData((CFDataRef)imageData, NULL);

NSDictionary *metaData = (NSDictionary *)CGImageSourceCopyPropertiesAtIndex(source,0,NULL);
NSDictionary *exifData = [metaData objectForKey:@"{Exif}"];
NSDictionary *tiffData = [metaData objectForKey:@"{TIFF}"];

//read-in pictures

[metaData release];
CFRelease(source);

No comments:

Post a Comment