Fixing dark borders sprites on IPhone
I ran into this issue a couple hours ago working on the IPhone sdk:
See the darker borders around the image?
It’s a png image and that’s was supposed to be a gradient of alpha. So why am I getting this strange stuff around it?
The first thing I found out is that XCode grabs the png images and multiplies the RGB component with the alpha. So you can understand now why only 0 or 1 works right? Everything in between get’s changed. This is why Apple recommends using PNG over JPGS, although they consume more space they are altered for speed.
This is refereed as using images with pre-multiplied alpha.
If you don’t care about this and just want to use regular alpha blend one quick fix up for this is on each image load to reset the correct RGB values and maintain the A component
There may be other solutions but this won’t have any impact on the game, just when loading images. Let me know if you find any other solution.
EDIT: Quick note here: this is not the correct way to deal with pre-multiplied alpha but a patching. XNA recently embraced pre multiplied alpha to avoid this issues. More here (Thanks Elisée Maurer)