Hi, i am trying to “capture” Unitys screen and use the bitmap data to create an UIImage in xCode.
While i had some success, it´s not good enough. Here is the one that works, when Anti Aliasing is NOT used. If that is used, you only get an error and a black image.
- in unity have some script like this:
public function xCodeCaptureScreenshot(filename : String) {
Application.CaptureScreenshot(filename);
}
You can call that from within Unity, i am calling it from xCode like this:
- (IBAction) shareOneImage:(id)sender {
NSString *screenShotFileName = @"unityScreenshot.png";
UnitySendMessage("xcodeReciever", "xCodeCaptureScreenshot", [screenShotFileName UTF8String]);
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *uniquePath = [docDir stringByAppendingPathComponent: screenShotFileName];
UIImage *theImage = [UIImage imageWithContentsOfFile:uniquePath ];
}
Ok, this works, the png is written to the documents directory. The file is saved asynchronous, so actually you need some delay befor you can read the file. If you just use this script, you will only see a part of the image, or nothing, or get an error, depending on your devices speed i guess.
By the way, on iPhone4 you only get a 480x360 image, so thats not so nice. This and the fact, that this doesn´t work with the new MSAA feature - you only will see a OpenGLES error 0x0502 in PresentSurface:651 Error, makes it somewhat unusable for me.
So my next attempt was the normal objective C way:
- (UIImage*) makeUnityScreenShot {
UIGraphicsBeginImageContextWithOptions(theUnityView.bounds.size, theUnityView.opaque, 0.0);
[theUnityView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return viewImage;
}
Well, from this i get a black image. Apparently UIGraphicsGetImageFromCurrentImageContext() doesnt work with EAGLview.
But maybe i just have a small issue in this and somebody could give me hint.
Last thing i can think of is to somehow read out the buffers. But i have no clue how to do this.
A normal device Screenshot is also not wanted, cause i have GUI elements on top of unity which i don´t want to have inside the resulting image.
Any help is welcome, i am running out of time with my schedule…:shock: