Tomo.Log()


The PNG transparency bug in iOS 15

[04/05, 2022]

English / 日本語

Note that I got stuck with the PNG transparency bug in iOS and spent an awful lot of time on it.

There are known bugs in iOS, but the one I encountered this time seems to be a bit different.

Known bugs

iOS13: There seems to be a phenomenon where transparency is lost when PNGs with transparency are loaded in the app.
iOS15.1: The background of transparent PNGs seems to be filled with white.

Bugs encountered this time

TL;DR.

PNGs with one side less than 360px lose transparency information in iOS.

This is what I encountered.

The reason I wrote in iOS is that when I Airdrop to Mac, the transparency information still remains and the image is displayed with transparency as usual.

The reason why I ran into this bug in the first place is that I was trying to create a CGContext with init and export a png, but it was not transparent and I had trouble.

At first, I thought that the BitmapInfo setting was wrong and was trying this and that to fix it, but suddenly I wondered what if I used the context obtained by "UIGraphicsGetCurrentContext" to save the png. I tried it and was able to successfully output the image I wanted.

The difference between the UIGraphicsGetCurrentContext and the context that I created by myself was the size setting; although the size was different, the aspect ratio was the same. Before obtain the context via "UIGraphicsGetCurrentContext", call
"UIGraphicsBeginImageContextWithOptions". And this method set the scale as 2 implicitly, and I notice that the size is double the size of the original.

So I doubted the size has something. And then I tried double size with the context I created by myself, It worked!

What's the secret behind doubling the size? I really don't know why, but I changed the size a little bit and got to the threshold value "360" manually 😂.

I don't know what the secret is behind 360, but if it is 361px or more, it works fine (mystery!).

I just thought this is a good thing even though I spent a lot of time because I got one topic to write a blog lol. And start working hard again tomorrow.