【发布时间】:2013-10-30 01:19:21
【问题描述】:
在研究和尝试了很多事情之后,我终于让自己问了这样一个问题:
基本上我想挑选一张照片,然后将其渲染到 CIcontext,因为我知道还有许多其他可用的图像渲染技术(例如,使用 UIImageView 等),我必须使用低级 OpenGL ES 渲染。
请查看我的完整代码(AppDelegate中的UIImagePickerController预加载除外)
#import "ViewController.h"
#import "AppDelegate.h"
#import <GLKit/GLKit.h>
@interface ViewController () <GLKViewDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate> {
GLKView *glkview;
CGRect glkview_bounds;
}
- (IBAction)click:(id)sender;
@property (strong, nonatomic) EAGLContext *eaglcontext;
@property (strong, nonatomic) CIContext *cicontext;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.eaglcontext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
glkview = [[GLKView alloc] initWithFrame:[[UIScreen mainScreen] bounds] context:self.eaglcontext];
glkview.drawableDepthFormat = GLKViewDrawableDepthFormat24;
glkview.enableSetNeedsDisplay = YES;
glkview.delegate = self;
[self.view addSubview:glkview];
[glkview bindDrawable];
glkview_bounds = CGRectZero;
glkview_bounds.size.width = glkview.drawableWidth;
glkview_bounds.size.height = glkview.drawableHeight;
NSLog(@"glkview_bounds:%@", NSStringFromCGRect(glkview_bounds));
self.cicontext = [CIContext contextWithEAGLContext:self.eaglcontext options:@{kCIContextWorkingColorSpace : [NSNull null]} ];
UIAppDelegate.g_mediaUI.delegate = self;
}
- (IBAction)click:(id)sender {
[self presentViewController:UIAppDelegate.g_mediaUI animated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[self dismissViewControllerAnimated:NO completion:nil];
UIImage *pre_img = (UIImage *)[info objectForKey:UIImagePickerControllerOriginalImage];
CIImage *outputImage = [CIImage imageWithCGImage:pre_img.CGImage];
NSLog(@"orient:%d, size:%@, scale:%f, extent:%@", (int)pre_img.imageOrientation, NSStringFromCGSize(pre_img.size), pre_img.scale,NSStringFromCGRect(outputImage.extent));
if (outputImage) {
if (self.eaglcontext != [EAGLContext currentContext])
[EAGLContext setCurrentContext:self.eaglcontext];
// clear eagl view to grey
glClearColor(0.5, 0.5, 0.5, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
// set the blend mode to "source over" so that CI will use that
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
[self.cicontext drawImage:outputImage inRect:glkview_bounds fromRect:[outputImage extent]];
[glkview display];
}
}
@end
什么有效: 挑选具有大小的图像,例如。显示尺寸为 1390x1390 或 1440x1440。
什么不行:不显示2592x1936大小的图片,基本上都是用相机拍摄的大图。
请帮助找出解决方案,我被困在这里......
【问题讨论】:
-
很遗憾没有。我尝试了很多变化。我还看到了一个关于这个主题的 WWDC 会议,但它的源代码还没有发布(可能还没有发布)。它是 wwdc2012/511:核心图像技术。我检查了源代码 dmg,但它不包含会话 511 源代码...
-
此解决方案不适用于 ios 10.2
标签: iphone xcode uiimage core-image glkview