I am trying to get a UIImage from what is displayed in my EAGLView. Any suggestions on how to do this?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- how do you prevent page scroll in textarea on mobi
- Custom UITableview cell accessibility not working
相关文章
- Could I create “Call” button in HTML 5 IPhone appl
- Unable to process app at this time due to a genera
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
- Open iOS 11 Files app via URL Scheme or some other
- Why is glClear blocking in OpenGLES?
- Can keyboard of type UIKeyboardTypeNamePhonePad be
- Can not export audiofiles via “open in:” from Voic
With this above code of Brad Larson, you have to edit your EAGLView.m
You have to change
numberWithBool
valueYES
EDIT: as demianturner notes below, you no longer need to render the layer, you can (and should) now use the higher-level
[UIView drawViewHierarchyInRect:]
. Other than that; this should work the same.An
EAGLView
is just a kind of view, and its underlyingCAEAGLLayer
is just a kind of layer. That means, that the standard approach for converting a view/layer into a UIImage will work. (The fact that the linked question is UIWebview doesn't matter; that's just yet another kind of view.)Here is a cleaned up version of Quakeboy's code. I tested it on iPad, and works just fine. The improvements include:
Use this as a method in your EAGLView:
I was unable to get the other answers here to work correctly for me.
After a few days I finally got a working solution to this. There is code provided by Apple which produces a UIImage from a EAGLView. Then you simply need to flip the image vertically since UIkit is upside down.
Apple Provided Method - Modified to be inside the view you want to make into an image.
}
And heres a method to flip the image
}
And here's a link to the Apple dev page where I found the first method for reference. http://developer.apple.com/library/ios/#qa/qa1704/_index.html
CGDataProviderCreateWithData
comes with a release callback to release the data, where you should do the release:Then do this like other examples, but NOT to free data here:
Or simply use
CGDataProviderCreateWithCFData
without release callback stuff instead:For more information, please check this discuss:
What's the right memory management pattern for buffer->CGImageRef->UIImage?