hi,
is it possible to create a screenshot in my app?
i want to send the screenshot with the mail default mail app.
A fast, easy to use, free, and community supported 2D game engine
hi,
is it possible to create a screenshot in my app?
i want to send the screenshot with the mail default mail app.
--->>> http://code.google.com/p/cocos2d-iphone/issues/detail?id=533
this creates me the screenshot ... to a Texture2D Object... but how can i save this and send it per mail? :-)
One thing I just recently learned about:
http://blog.mugunthkumar.com/coding/iphone-tutorial-in-app-email/
https://developer.apple.com/iphone/library/samplecode/MailComposer/index.html
(edit) its for 3.0 only
MailComposer includes code for pre-3.0. The only catch is that it launches the mailer so you leave your app. Also there is no way (at least from all the reading I have done) to include an attachment so it won't work for your screenshot. :-(
and works only with UI defaul Views :-( ... is there no way to send emails with attachments in cocos2d?
I have edited the screenshot code:
http://www.cocos2d-iphone.org/forum/topic/1722#post-11643
With:
[[Director sharedDirector] screenShotUIImage]; //return a UIImage
[[Director sharedDirector] screenShotTexture2D]; //return a Texture2D
Hi, we base64 encode the image, upload to our server and send from there... you could possibly use this device side by sending HTML email, ie., multipart MIME messages with the image embedded as base64 text.
--yarri
It is possible to integrate the mailer stuff using the UIKit integration sample as a base; I've done it as part of my game. It is somewhat involved though. Once I get clear of the release process (waiting on Apple and busy trying to get marketing info and lite version done) I'll try to extract the appropriate code and post it somewhere.
Sorry I can't do more at the moment.
i've copied the diplay function ... but i can only see the toolbar of the mail editor on the top?!
-(void)displayComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Hello from California!"];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"first@example.com"];
NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil];
NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"];
[picker setToRecipients:toRecipients];
[picker setCcRecipients:ccRecipients];
[picker setBccRecipients:bccRecipients];
// Attach an image to the email
NSString *path = [[NSBundle mainBundle] pathForResource:@"button" ofType:@"png"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"button"];
// Fill out the email body text
NSString *emailBody = @"It is raining in sunny California!";
[picker setMessageBody:emailBody isHTML:NO];
[[picker view] setFrame:CGRectMake(0.0f,0.0f,320.0f, 480.0f)];
[[[VariableStore sharedInstance] window]addSubview:picker.view];
[[[VariableStore sharedInstance] window] makeKeyAndVisible];
[picker release];
}
For attach a screenshot
// Attach an image to the email
UIImage *screenshot = [[Director sharedDirector] screenShotUIImage];
NSData *myData = UIImagePNGRepresentation(screenshot);
[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"screenshot"];
THX manucorporat..... it works.. 1 problem remaining ... (can only see the toolbar of the maileditor)
I had the same problem for quite a while. I am not sure if this solved the problem but my working version uses a view controller. I think the key is that I attach the controller's view to openGLView and use the controller to auto-rotate the view into my chosen landscape orientation. However, I played around with some many parameters while trying to get it to work I can't say for certain that everything is needed.
Here is the implementation:
@implementation ChallengeMailViewController
- (void)loadView {
self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
self.wantsFullScreenLayout = YES;
UIView *view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
view.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
view.backgroundColor = [UIColor clearColor];
view.clearsContextBeforeDrawing = NO;
view.opaque = NO;
self.view = view;
[view release];
}
- (void)displayMailComposer {
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:challengeMailSubject()];
[picker setMessageBody:challengeMailBody(NO) isHTML:NO];
// Attempt to load the high-score image
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[HighScores imageFilename]];
NSData *imageData = [NSData dataWithContentsOfFile:fullPath];
[picker addAttachmentData:imageData mimeType:@"image/png" fileName:@"highscore"];
[self presentModalViewController:picker animated:YES];
[picker release];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
#pragma mark -
#pragma mark MFMailComposeViewControllerDelegate
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
}
@end
@manucorporat: the screenshot function is to fast or the director toooooo slow. I want to remove some sprites befor i take a screenshot... first try:
[sprite setVisible:NO];
// screenshotactionhere;
2nd try:
[sprite setPosition:ccp(10000000,1000000)];
//screenshitactionhere
...
how can I refresh the screen for the screenshotfunction after the setVisible tag?
I haven't understood you something.
You can remove a sprite named "sprite" using:
[[sprite parent] removeChild:sprite cleanup:YES];
For ocult the sprite you should use:
[sprite setVisible:NO];
not use: [sprite setPosition:ccp(10000000,10000000)];
NOTE:
Screenshot method still is not implemented in cocos2D official source. I am waiting for riq approval it. In: http://code.google.com/p/cocos2d-iphone/issues/detail?id=533
//Create a sprite with the screenshot
Sprite *sprite = [Sprite spriteWithTexture:[[Director sharedDirector] screenshotTexture2D]];
//You can refresh the sprite using:
[sprite setTexture:[[Director sharedDirector] screenshotTexture2D]];I think I had the same issue as raegtime when using similar code from Slipster a while back, I haven't got round to fixing it yet, and I haven't tried your method yet either.
The problem for me was if you remove a sprite and then take the screen shot straight away, the redraw hasn't taken place, and the sprite is still visible. I was planning to try adding a small delay before calling the texture grab code, that might work.
no the name sprite was an example :-) ... on the screen there is a background pic named bg (type = sprite) and some other pictures (type sprite)... when i try to take a screenshot from the sprite "bg" without the other small pics, it doesent work, because the screenshot function takes a screenshot of all sprites.... i've set the pics visible property to "NO" before i run the screenshotfunction... but the screenshot shows the background AND the pics
Hi!
I read everything but a question... I tried to write a mail using your samples above.. but seems to works but how can I remove the picker view and come back to my scene?
thanks
You must log in to post.