Pages

Thursday 18 December 2014

Capture Screenshot and save in Mac app ( cocoa )





Following code can explain you to capture screen and save it to specified format


// Follows code can capture the screenshot (in .png) and save it on specified folder

- (IBAction)SavePNG_BtnClicked:(id)sender
{

    CGDirectDisplayID displayID = CGMainDisplayID();
    CGImageRef imageRef = CGDisplayCreateImage(displayID); //screenshot
    
    NSString *path = [@"~/Desktop/public.png" stringByExpandingTildeInPath];
    [self savePNGImage:imageRef path:path];
    
    CFRelease(imageRef);
    
}



// Follows code can capture the screenshot (in .jpeg) and save it on specified folder

- (IBAction)SaveJPEG_BtnClicked:(id)sender
{
    CGDirectDisplayID displayID = CGMainDisplayID();
    CGImageRef imageRef = CGDisplayCreateImage(displayID); //screenshot
    
    NSString *path = [@"~/Desktop/public.jpeg" stringByExpandingTildeInPath];
    [self saveJPEGImage:imageRef path:path];
    
    CFRelease(imageRef);
}



// Follows code can capture the screenshot (in .tiff) and save it on specified folder

- (IBAction)SaveTIFF_BtnClicked:(id)sender
{
    CGDirectDisplayID displayID = CGMainDisplayID();
    CGImageRef imageRef = CGDisplayCreateImage(displayID); //screenshot 
   
    
    NSString *path = [@"~/Desktop/public.tiff" stringByExpandingTildeInPath];
    [self saveTIFFImage:imageRef path:path];
    
    CFRelease(imageRef);
    

}

No comments:

Post a Comment