Вот код. У меня есть URL-адрес изображения. После его успешной загрузки я пытаюсь использовать данные или UIImagePNGRepresentation (изображение), все они отображаются неправильно.
Код: Выделить всё
[[[NSURLSession sharedSession] dataTaskWithURL:[NSURL URLWithString:@"http://lxcode.bs2cdn.yy.com/da3d9ae1-93a0-4149-9977-babee7ad2fb8.png"] completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
UIImage *tempImg = [UIImage imageWithData:data];
CGImageRef cgRef = tempImg.CGImage;
MTKTextureLoader *loader = [[MTKTextureLoader alloc] initWithDevice:device];
id temp1 = [loader newTextureWithData:data options:@{MTKTextureLoaderOptionSRGB: @(NO), MTKTextureLoaderOptionTextureUsage: @(MTLTextureUsageShaderRead), MTKTextureLoaderOptionTextureCPUCacheMode: @(MTLCPUCacheModeWriteCombined)} error:nil];
NSData *tempData = UIImagePNGRepresentation(tempImg);
id temp2 = [loader newTextureWithData:tempData options:@{MTKTextureLoaderOptionSRGB: @(NO), MTKTextureLoaderOptionTextureUsage: @(MTLTextureUsageShaderRead), MTKTextureLoaderOptionTextureCPUCacheMode: @(MTLCPUCacheModeWriteCombined)} error:nil];
id temp3 = [loader newTextureWithCGImage:cgRef options:@{MTKTextureLoaderOptionSRGB: @(NO), MTKTextureLoaderOptionTextureUsage: @(MTLTextureUsageShaderRead), MTKTextureLoaderOptionTextureCPUCacheMode: @(MTLCPUCacheModeWriteCombined)} error:nil];
}] resume];
[img]https://i.sstatic .net/Z41FsTTm.png[/img]
Неверное изображение после использования MTKTextureLoader:

Подробнее здесь: https://stackoverflow.com/questions/792 ... d-png-data