2012-09-11 4 views

Répondre

2

Quelque chose comme ceci:

float width = 10.0; 
float height = 10.0; 

NSImage *finalImage = [[NSImage alloc] initWithSize:NSMakeSize(width, height)]; 

// obtain images - your sources may vary 
NSImage *overlay = [[NSImage alloc] initWithData:[NSData dataWithContentsOfFile:@"/path/to/overlay_image.jpg"]]; 
NSImage *mainImage = [[NSImage alloc] initWithData:[NSData dataWithContentsOfFile:@"/path/to/main_image.jpg"]]; 

[finalImage lockFocus]; 

// draw the base image 
[mainImage drawInRect:NSMakeRect(0, 0, width, height) 
         fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0]; 

// draw the overlay image at some offset point 
[overlay drawInRect:NSMakeRect(10, 10, [overlay size].width, [overlay size].height) 
      fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0]; 

[finalImage unlockFocus]; 

NSData *finalData = [finalImage TIFFRepresentation]; 

[[[NSBitmapImageRep imageRepWithData:finalData] representationUsingType:NSJPEGFileType properties:nil] writeToFile:[NSString stringWithFormat:@"/path/to/folder/new_image.jpg"] atomically:YES];