Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Crop image in mac os

    • 0
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 615
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: