Save to Library

Discussion in 'iOS Development' started by Rockstarou812, Mar 26, 2009.

  1. Rockstarou812

    Rockstarou812 New Member

    Joined:
    Jan 17, 2009
    Messages:
    43
    Likes Received:
    0
    All I want is to have the save screenshot command (Hold Home+Sleep Button at the same time) to be activated when you click a UIButton. How would I do this? I checked the documentation with no luck.
  2. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    There actually is a one line method hidden deep within the frameworks, but I can't remember what it is right now. In the meantime, something like this should suffice.
    Code:
    	UIGraphicsBeginImageContext(self.view.frame.size);
    	[(YourAppDelegate *)[[UIApplication sharedApplication] delegate].window.layer renderInContext:UIGraphicsGetCurrentContext()];
    	UIImage *capturedScreen = UIGraphicsGetImageFromCurrentImageContext();
    	UIGraphicsEndImageContext();
    	
    	UIImageWriteToSavedPhotosAlbum(capturedScreen, nil, nil, nil);
    
  3. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    Hey, that's a pretty nifty little trick there. Say you use UIGraphicsBeginImageContext() with a specific CGSize, will the UIImage be sized that way?
  4. Rockstarou812

    Rockstarou812 New Member

    Joined:
    Jan 17, 2009
    Messages:
    43
    Likes Received:
    0
    Skylar, thanks so much for that code, How would I use it? As in what file should I put it in? And how should I add the button to it?

Share This Page