Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-23-2011, 02:58 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 2
r31shill is on a distinguished road
Default Xcode, code to screenshot the screen?

Looking to make a button which will take the image which is on screen,
linking it to a button so once 'touched up inside' the button it shall do the
command.

Any help is appreciated,
Thank You
r31shill is offline   Reply With Quote
Old 08-23-2011, 03:09 PM   #2 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Link your button to an IBAction method. In the method put the code found in this link: iphone - How to take a screenshot programmatically - Stack Overflow

In the future please use Google.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 08-23-2011, 04:04 PM   #3 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 17
appcody is on a distinguished road
Question

Quote:
Originally Posted by Domele View Post
Link your button to an IBAction method. In the method put the code found in this link: iphone - How to take a screenshot programmatically - Stack Overflow

In the future please use Google.
Hi,

Domele: Thanks for the reply
I have been having the same issues lately as well. You sent r31shill a link, and it is kind of complicated. I can copy and paste, but I don't know where! He has an IBAction, but the code on the website doesn't tell in which controller file to put it in. Do you know?

Thanks in advance,
appcody is offline   Reply With Quote
Old 08-23-2011, 04:07 PM   #4 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

What? You put it in whichever controller you need it to be in. If you want to take a screenshot in your first view, put in your first view controller, if you want it in your second view, put it in your second view controller.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 08-24-2011, 04:50 PM   #5 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 17
appcody is on a distinguished road
Question Doesn't work!

Hi,

I tried doing that though in a window based application, and the app wouldn't save the snapshot to my photo library. I am currently using a simulator though.

This is my .m code:
Code:
#import "snaptestAppDelegate.h"

@implementation snaptestAppDelegate

@synthesize window;

-(IBAction) getsnapshot {
	
	UIGraphicsBeginImageContext(self.window.bounds.size);
	[self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
	UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
	UIGraphicsEndImageContext();
	NSData * data = UIImagePNGRepresentation(image);
	[data writeToFile:@"foo.png" atomically:YES];
	
}

#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    
    // Override point for customization after application launch.
    
    [self.window makeKeyAndVisible];
    
    return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    /*
     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
     */
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    /*
     Called as part of  transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
     */
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     */
}


- (void)applicationWillTerminate:(UIApplication *)application {
    /*
     Called when the application is about to terminate.
     See also applicationDidEnterBackground:.
     */
}


#pragma mark -
#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    /*
     Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
     */
}


- (void)dealloc {
    [window release];
    [super dealloc];
}


@end
and this is my .h code:
Code:
#import <UIKit/UIKit.h>

@interface snaptestAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
}
-(IBAction) getsnapshot;

@property (nonatomic, retain) IBOutlet UIWindow *window;

@end
I linked the button to the xib and did touch up inside. Didn't work though. Do you know what could be the problem?

Thanks in advance,
appcody is offline   Reply With Quote
Reply

Bookmarks

Tags
apple developers, iphone, sdk, xcode

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 397
15 members and 382 guests
7twenty7, chiataytuday, cristofercolmbos, dedeys78, fiftysixty, gmarro, iOS.Lover, jonathandeknudt, kilobytedump, Matrix23, raymng, stanny, tymex, UMAD, xerohuang
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,669
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, dedeys78
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:13 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0