objective-cuiimagesprite-kitsktexture

UIImage from SKTexture


How to get UIImage from SKTexture?

I tried to get UIImage from SKTextureAtlas, but it seems not working too:

// p40_prop1 is a part of SKTextureAtlas
UIImage *image = [UIImage imageNamed:@"p40_prop1"];

image is nil.


Solution

  • Starting from iOS 9 it is a piece of cake. SKTexture now has CGImage property, which is of CGImageRef type. So getting image from a texture is just one line now:

    let image : UIImage = UIImage(CGImage:texture.CGImage)