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

    • 0
    • 2
    • 2
    • 1
    • 0
    • 0
    • 0
    • 0
    • 434
    Comment on it
       -(NSImage*)rotateImage:(CGFloat)degrees
        {
            NSImage *_image = [YourImageController image];
            NSRect imageBounds = {NSZeroPoint, [_image size]};
    
            NSBezierPath *boundsPath = [NSBezierPath bezierPathWithRect:imageBounds];
    
            NSAffineTransform *transform = [NSAffineTransform transform];
    
            [transform rotateByDegrees:degrees];
            [boundsPath transformUsingAffineTransform:transform];
    
            NSRect rotatedBounds = {NSZeroPoint, [boundsPath bounds].size};
    
            NSImage *rotatedImage = [[NSImage alloc] initWithSize:rotatedBounds.size];
               imageBounds.origin.x = NSMidX(rotatedBounds) - (NSWidth (imageBounds) / 2);
            imageBounds.origin.y = NSMidY(rotatedBounds) - (NSHeight (imageBounds) / 2);
    transform = [NSAffineTransform transform];
    
        [transform translateXBy:+(NSWidth(rotatedBounds)/ 2) yBy:+(NSHeight(rotatedBounds) / 2)];
    
    [transform rotateByDegrees:degrees];
    
        [transform translateXBy:-(NSWidth(rotatedBounds)/ 2) yBy:-(NSHeight(rotatedBounds) / 2)];
    [rotatedImage lockFocus];
    [transform concat];
    
        [_image drawInRect:imageBounds fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0] ;
            [rotatedImage unlockFocus];
            return rotatedImage;
        }
    

 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: