If you want to crop the image without changing its quality in Objective-c/cocoa (OSX) then you can use the following method
-(IBAction)crop:(id)sender{
hasBeenDragged = NO;
NSImage *_sourceImage = [self image];
float width = selectedArea.size.width;
float height = selectedArea.size.height;
float xPos = selectedArea.origin.x;
float yPos = selectedArea.origin.y;
float centerX = ([self frame].size.width/2)-width/2;
float centerY = ([self frame].size.height/2)-height/2;
NSImage *_alteredImage = [[NSImage alloc]initWithSize:[_sourceImage size]];
[_alteredImage lockFocus];
[_sourceImage drawAtPoint:NSMakePoint(centerX,centerY) fromRect:NSMakeRect(xPos, yPos, width, height+50) operation:NSCompositeSourceOver fraction:1.0];
[_alteredImage unlockFocus];
[self setImage:_alteredImage];
[self setNeedsDisplay:YES];
}
0 Comment(s)