研究,最後嘗試許多事情之後我自己問這樣:如何將UIImage(從照片庫中選取)渲染到CIContext/GLKView中?
基本上我想挑選一張,然後使它對一個CIcontext,知道許多其它的圖像渲染技術(如:使用UIImageView
等),我必須使用低級的OpenGL ES渲染。
請查看我的完整代碼(除的UIImagePickerController
在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的圖像未顯示,基本上都是用相機拍攝的所有大圖。
請幫忙找出解決辦法,我在這裏stucked ...
得到了什麼解決方案? –
可悲的是..我嘗試了很多變化。我也看到了關於這個主題的WWDC會議,但是它的源代碼沒有發佈(可能還有)..它是wwdc2012/511:核心圖像技術。我檢查了源代碼dmg,但它沒有包含會話511源代碼... – zZzZ
此解決方案無法在ios 10.2上工作 – khunshan