ios - Core Graphics 和 Open GL 绘图

标签 ios opengl-es uiimageview core-graphics

我有一个绘图应用程序,我在其中使用 openGL 绘图代码绘制笔划,但想在笔划完成后将其传输到另一个图像,然后清除 OpenGL View 。为此,我正在使用 CoreGraphics。然而,我遇到了一个问题,在通过 CG 传输图像之前清除了 OpenGL View (即使我之后清除了它)

(我想要另一种方式,即先绘制图像,然后删除绘画图像,以避免任何类型的闪烁)

(paintingView 是 openGL View )

代码如下:

// Save the previous line drawn to the "main image"

UIImage *paintingViewImage = [[UIImage alloc] init];
paintingViewImage = [_paintingView snapshot];

UIGraphicsBeginImageContext(self.mainImage.frame.size);
[self.mainImage.image drawInRect:CGRectMake(0, 0, self.mainImage.frame.size.width, self.mainImage.frame.size.height) blendMode:kCGBlendModeNormal alpha:1.0];

// Get the image from the painting view

[paintingViewImage drawInRect:CGRectMake(0, 0, self.mainImage.frame.size.width, self.mainImage.frame.size.height) blendMode:kCGBlendModeNormal alpha:1.0];
self.mainImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

[self.paintingView erase];

因此,在将 mainImage.image 变量设置为 CurrentImage 上下文之前,将删除 paintingView。

我只是这些方面的初学者,所以任何想法都有帮助。

谢谢

最佳答案

您最好使用 FBO(OpenGL 帧缓冲对象)。您绘制到一个 FBO 中,然后在保存前一个 FBO 的同时将绘图切换到一个新的 FBO。您可以在 2 个 FBO 之间来回切换。 Here are the docs在 iOS 上使用 FBO

关于ios - Core Graphics 和 Open GL 绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19609657/

相关文章:

ios - 点击手势在 imageView 中不起作用,但它在另一个 View 中起作用

ios - 为什么 UIImageview 不是完美的圆?

ios - 在非基于文档的应用程序中保存数据

android - 来自 glSurfaceView 的位图为空

android - java.lang.RuntimeException : eglSwapBuffers failed: EGL_SUCCESS

java - 纹理浮桥 - 旋转问题

ios - UICollectionview cell/imageview 不会全屏点击

objective-c - 为什么 UIView :animateWithDuration complete immediately?

ios - 我可以打电话 - (void)touchesBegan :(NSSet *)touches withEvent:(UIEvent *)event on subview

iOS : Universal framework is creating issue while submitting to app store