I guess Application.CaptureScreenshot doesn’t work on the iPhone?
No, but you can user XCode Organizer to capture and retrieve your screenshots.
And also Home+Power buttons on the device saves a screenshot that can be imported into iPhoto.
Thanks technicat, that is a really useful one!
Yeah, but I’m looking for a programmatic way to capture the screen.
How about ReadPixels() + EncodeToPNG()?
–Eric
Well, yeah that should work! Thanks Eric!
I know this is an old thread, but is there a way to save this screen capture image into the iPhone camera roll?
This may be possible with bliprob’s enhancement pack.
You can now also use UIGetScreenImage() in XCode. This used to be a private API, but Apple publicly released it not too long ago. The real advantage of this method is, that compared to glReadPixels() its pretty easy to implement and it captures your screen no matter what (transparency, etc…).
In XCode you have to add the following lines of code to the .m file that later calls UIGetScreenImage();
//add right below #import lines
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
Then you can use the following method to capture your screen and save the image to your photo library:
- (void)saveScreenshotToPhotolibrary {
UIImageWriteToSavedPhotosAlbum([UIImage imageWithScreenContents], nil, nil, nil);
}
Thanks a lot!!!
Works!
Hello!
I’m trying to use this piece of code but I don’t seem to be doing it right.
Is this supposed to be used as a plugin?
I tried copying it on a .mm file but I’m getting a linking error during project compilation in XCode.
Basically I’ve created a new .mm file and pasted the previous piece of code and then added
extern "C"
{
void sameMethodName ()
{
UIImageWriteToSavedPhotosAlbum(blablabla);
}
}
I guess it’s not because of this that I’m getting this error cause it’s a linking error to UIGetScreenImage() and _CGImageRelease
I fell a little bit lost on this one
Thanks in advance!
Edit: To answer my own question. I was using a .mm file so I needed to write this line like this.
UIKIT_EXTERN CGImageRef UIGetScreenImage();
The plugin worked, well sort of I got a linking error on CGImageRelease too but I tagged that line just to test… it seems a little bit slow to use this and also seems like it doesn’t fit what I need to do later with the image.