在研究和尝试了很多事情之后,我终于让自己问了这样一个问题:
基本上我想选择一张照片,然后将其渲染到 CIcontext,知道许多其他可用的图像渲染技术(例如 useUIImageView
等),我必须使用低级 OpenGL ES 渲染。
请检查我的完整代码(UIImagePickerController
in的预加载除外AppDelegate
)
#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的拾取图像,基本上都是用相机拍摄的大图。
请帮助找出解决方案,我被困在这里...