gpt4 book ai didi

iphone - 如何将 UIImage(从照片库中选取)渲染到 CIContext/GLKView 中?

转载 作者:行者123 更新时间:2023-12-03 20:04:59 25 4
gpt4 key购买 nike

经过研究和尝试很多事情后,我终于问自己:

基本上我想选择一张照片,然后将其渲染到 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尺寸的图片不显示,基本上都是用相机拍摄的大图片。

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

最佳答案

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

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

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

来源:Black texture with OpenGL when image is too big

关于iphone - 如何将 UIImage(从照片库中选取)渲染到 CIContext/GLKView 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19496383/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com