3

在研究和尝试了很多事情之后,我终于让自己问了这样一个问题:

基本上我想选择一张照片,然后将其渲染到 CIcontext,知道许多其他可用的图像渲染技术(例如 useUIImageView等),我必须使用低级 OpenGL ES 渲染。

请检查我的完整代码(UIImagePickerControllerin的预加载除外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的拾取图像,基本上都是用相机拍摄的大图。

请帮助找出解决方案,我被困在这里...

4

1 回答 1

1

OpenGL 有纹理限制,取决于 iOS 设备,它可以是 2048x2048。您可以使用以下代码检查设备的最大纹理限制:

static GLint maxTextureSize = 0;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);

较旧的设备(iPhone 4S 之前)的最大纹理尺寸均为 2048x2048。A5 及以上(包括 iPhone 4S 之后)具有最大 4096x4096 纹理大小。

来源:图像太大时使用 OpenGL 的黑色纹理

于 2013-10-30T22:55:17.663 回答