【发布时间】:2011-10-26 05:36:07
【问题描述】:
我有一个想要转换为 UIImage 的 EAGLView。我可以使用此处发布的解决方案来做到这一点:
How to get UIImage from EAGLView?
但是,如果在创建 EAGLView 和 UIImage 之间经过了一小段时间,我只能完成此操作。
这段代码,它创建了一个 EAGLView,然后是一个 UIImageView,它不起作用:
EAGLView *EAGLphoto = [[EAGLView alloc] initWithImage:photo.workAreaImage];
[theWorkArea.photoArea1 addSubview:EAGLphoto];
//I put a glfinish() here but it didn't help
UIImageView *photoView = [[UIImageView alloc] initWithImage:[self glToUIImage]];
//glToUIImage is taken from the link above
[theWorkArea.photoArea2 addSubview:photoView];
我假设 UIImageView 尝试在 EAGLView 完成创建之前创建。我试图在两者之间放置一个 glfinish() 但它什么也没做。当我运行代码时,EAGLView 显示正常,但 UIImageView 显示为黑色。
但是,上面代码的这个修改版本可以工作:
EAGLView *EAGLphoto = [[EAGLView alloc] initWithImage:photo.workAreaImage];
[theWorkArea.photoArea1 addSubview:EAGLphoto];
[self performSelector:@selector(getUIImage) withObject:nil afterDelay:0.1];
- (void)getUIImage {
UIImageView *photoView = [[UIImageView alloc] initWithImage:[self glToUIImage]];
//glToUIImage is taken from the link above
[theWorkArea.photoArea2 addSubview:photoView];
}
我是否错误地使用了 glfinish()?有没有比我的 hack 更好的方法?
【问题讨论】:
-
你试过 afterDelay:0.0 吗?这有助于诊断。
-
Tommy,添加 0.0 的延迟仍然有效,我不知道为什么。有什么想法吗?
标签: iphone ios uiview opengl-es eaglview