简体   繁体   English

使用GLKTextureLoader和imageNamed时出现问题:多次加载同一张图像时

[英]Issue using GLKTextureLoader and imageNamed: when loading same image multiple times

I get strange behaviour when I use the following code to load an image multiple times: 当我使用以下代码多次加载图像时,出现奇怪的行为:

NSDictionary *options = @{GLKTextureLoaderOriginBottomLeft: @YES};
textureInfo = [GLKTextureLoader textureWithCGImage:[UIImage imageNamed:@"name"].CGImage 
                                           options:options
                                             error:nil];

It works as expected when I run load the image the first time, but when I try to load the same image again it's drawn upside down. 第一次运行图像加载时,它可以按预期工作,但是当我再次尝试加载相同图像时,它会倒置。

I think this has to do with the fact that it's actually the same CGImage that gets passed to the texture loader because of the use of imageNamed:. 我认为这与以下事实有关:由于使用了imageNamed:,它实际上是传递给纹理加载器的CGImage。 The flip transformation is therefore applied a second time on the same image. 因此,翻转变换第二次应用于同一图像。

Is there a way to get around this issue? 有没有办法解决这个问题?

I guess you could flip the image, and load it the first time when your program starts. 我想您可以翻转图像,并在程序启动时第一次加载它。

Or not use imageNamed. 还是不使用imageNamed。 Or keep the texture in memory so you only have to load it once. 或者将纹理保留在内存中,因此您只需加载一次即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM