Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在UIImage到纹理转换中,纹理垂直翻转_Ios_Ios4_Opengl Es 2.0 - Fatal编程技术网

Ios 在UIImage到纹理转换中,纹理垂直翻转

Ios 在UIImage到纹理转换中,纹理垂直翻转,ios,ios4,opengl-es-2.0,Ios,Ios4,Opengl Es 2.0,我正在尝试在iOS平台上将UIImage读入纹理。我在StackOverflow上找到了实现这一技巧的代码片段,但问题是当我显示纹理时,它是倒挂显示的 int numComponents = 4; UIImage* image = [UIImage imageNamed:@"Test.png"]; CGImageRef imageRef = [image CGImage]; int width = CGImageGetWidth(imageRef); int height = CGImageG

我正在尝试在iOS平台上将UIImage读入纹理。我在StackOverflow上找到了实现这一技巧的代码片段,但问题是当我显示纹理时,它是倒挂显示的

int numComponents = 4;

UIImage* image = [UIImage imageNamed:@"Test.png"];
CGImageRef imageRef = [image CGImage];
int width = CGImageGetWidth(imageRef);
int height = CGImageGetHeight(imageRef);

//Allocate texture data
GLubyte* textureData = (GLubyte *)malloc(width * height * numComponents);    

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
NSUInteger bytesPerPixel = 4;
NSUInteger bytesPerRow = bytesPerPixel * width;
NSUInteger bitsPerComponent = 8;
CGContextRef context = CGBitmapContextCreate(textureData, width, height,
                                             bitsPerComponent, bytesPerRow, colorSpace,
                                             kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);

CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef);
CGContextRelease(context);

//texture setup
GLuint textureID;    
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &textureID);

glBindTexture(GL_TEXTURE_2D, textureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureDataMirrored);   
我还尝试使用以下行镜像UIImage(在读取数据之前),但它也不起作用。事实上没有任何影响

image = [UIImage imageWithCGImage:image.CGImage scale:image.scale orientation:UIImageOrientationUpMirrored]; 

请让我知道我做错了什么。谢谢。

这两行解决了这个问题

CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0,height);
CGContextConcatCTM(context, flipVertical);

这两条线解决了这个问题

CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0,height);
CGContextConcatCTM(context, flipVertical);

可能重复的感谢..它没有完全回答,但确实引导我找到了解决方案。如果你愿意,你可以接受你自己的解决方案。可能重复的感谢..它没有完全回答,但确实引导我找到了解决方案。如果你愿意,你可以接受你自己的解决方案。