CalebK Posted December 21, 2019 Posted December 21, 2019 Before I begin it is possible that this is a bug with Metal or MetalKit and not Affinity... However based on a few things my suspicion is that it is Affinity. So here is what happened. I created an ellipse with a radial gradient to transparency. I rasterized it. And tried to export it. I added it to my assets in Xcode and oddly enough it failed to load. Thinking that was odd I substituted in a picture I knew would load and it worked..... So I determined I must be exporting it wrong. I then open that png (that worked) in affinity resize the canvas and superimpose my transparent circle on it. I export it and put it in assets. It loads perfectly of course there is an unwanted background to this image. I then hide the layer and re-export thinking this will work. It did not. Instead it still failed to load into my app. Not even setting the layers opacity to 0% worked. The layer had to be at 1% opacity in order for the exported photo to work with my app. To summarize: For some reason I cant export a photo in a format that MetalKit will read and successfully load unless I add a layer that has a png that has an export that worked/loaded in at at least 1% opacity. This is 100% reproducible for me. Attached is a photo that would fail to load in Xcode and also a photo that did load in Xcode. I have also attached the affinity photo file that produces this un-importable image. The gradient is white and thus appears like a blank image here. And for those of you interested the image is loaded in through this code: - (id<MTLTexture>) textureFor:(NSString*)name { MTKTextureLoader* textureLoader = [[MTKTextureLoader alloc] initWithDevice:device]; NSDictionary *textureLoaderOptions = @{ MTKTextureLoaderOptionTextureUsage : @(MTLTextureUsageShaderRead), MTKTextureLoaderOptionTextureStorageMode : @(MTLStorageModePrivate) }; return [textureLoader newTextureWithName:name scaleFactor:1.0 bundle:nil options:textureLoaderOptions error:nil]; } I have also attached a zip file of an Xcode project (Version 11.3 (11C29)) ReproduceMetal.zip. If you build to your device it will crash with the image willFail which is currently loaded in. thisWillFail.afphoto ReproduceMetal.zip Quote
Staff MattP Posted January 3, 2020 Staff Posted January 3, 2020 Apple have known of this issue and reproduced it in 2017 - apparently their loader fails for greyscale/monochrome images (ie RGB images where the image contains only greys) when there is 0% transparency in the image. They have 2 workarounds - the first is to make the image slightly off-monochrome (!!!) and the second, better one, is: Store the image as an MTLTexture asset in Xcode and then the conversion is done at build time, not runtime and that will work. Hope that helps! Quote
CalebK Posted January 3, 2020 Author Posted January 3, 2020 7 hours ago, MattP said: Apple have known of this issue and reproduced it in 2017 - apparently their loader fails for greyscale/monochrome images (ie RGB images where the image contains only greys) when there is 0% transparency in the image. They have 2 workarounds - the first is to make the image slightly off-monochrome (!!!) and the second, better one, is: Store the image as an MTLTexture asset in Xcode and then the conversion is done at build time, not runtime and that will work. Hope that helps! Helps immensely thank you! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.