IPhone full screen sending

I am developing an iPhone application for creating images using embedded graphics and custom text.

I want to have my application with integrated graphics and custom text, which can then be sent as a single image (like a screenshot) to an email application for sending by email.

Is there a way to do this without taking a screenshot, leaving the application, entering the Photos application, selecting a screenshot and sending it by e-mail?

Ultimately, I would like to have a button in my application that the user could click, and the entire screen will be captured and sent directly to the mail application.

Any pointers gratefully accepted!

+2
email iphone screenshot
source share
6 answers

To expand Brentโ€™s answer, the following code will capture a screenshot and save it in the Documents folder as a PNG named screenshot.png:

UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow]; UIGraphicsBeginImageContext(screenWindow.frame.size); [screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); NSData *screenshotPNG = UIImagePNGRepresentation(screenshot); NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSError *error = nil; [screenshotPNG writeToFile:[documentsDirectory stringByAppendingPathComponent:@"screenshot.png"] options:NSAtomicWrite error:&error]; 

This is a little rude since it will leave a blank space at the top of the screen for the title and will not grab content from CAEAGLLayers.

Also, I donโ€™t think you can use the standard mailto: // URL construct, and then openURL, to send nested MIME attachments. Maybe the 3.0 SDK fixes this, but I still have to play with it. You may need to use something like sksmtpmessage to send a message directly from your application.

+5
source share

There is also a private UIGetScreenImage API. It is used like this:

 CGImageRef UIGetScreenImage(); @interface UIImage (ScreenImage) + (UIImage *)imageWithScreenContents; @end @implementation UIImage (ScreenImage) + (UIImage *)imageWithScreenContents { CGImageRef cgScreen = UIGetScreenImage(); if (cgScreen) { UIImage *result = [UIImage imageWithCGImage:cgScreen]; CGImageRelease(cgScreen); return result; } return nil; } @end 

This feature can be combined with UIImagePNGRepresentation to create PNGs.

+4
source share

Apple now allows apps to use;

 CGImageRef UIGetScreenImage(void); 

function. Although you should remember that it returns the stored CGImageRef, and you will have to manage your memory accordingly.

They also say that "... a future release of iPhone OS may provide a public API equivalent to this functionality. At this time, all applications using UIGetScreenImage () will need to use an open API."

+3
source share

skpsmtpmessage is excellent. If the fact is so good, I went, cloned it and added a sample project on github. The GUI example below adds a few bells and whistles, such as a progress bar and some other useful properties, but basically supports the basic skpsmtpmessage code.

http://github.com/kailoa/iphone-smtp/tree/master

+1
source share

I donโ€™t know if this will work, but you can try to create a graphics context with raster graphics support, and then get your Core Animation root mode and call its -renderInContext: method. It can do it, but I have never tried.

Perhaps, however, you should consider a different approach. Is it just that you wrote a bunch of custom drawing code that is displayed on the screen and you want to be able to draw to the memory or memory buffer? If so, perhaps you should consider that the drawing code is from your view and a separate object that is just being used by you. This will allow you to do this very easily in both directions.

0
source share

In OS 3.0, you can use MFMailComposeViewController:

 MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; picker.mailComposeDelegate = self; [picker addAttachmentData:screenshotPNG mimeType:@"image/png" fileName:@"PNGfromMyApp"]; 
0
source share

All Articles