When you load textures in a certain graphics mode (16-bit, 32-bit etc.), they're automatically converted to the same bit depth, regardless of the bit depth of the image file.
So, your code that writes to the alpha channel needs to take this into account since the bits used for RGBA will be different for all the graphics modes that use a different bit depth.
So, your code that writes to the alpha channel needs to take this into account since the bits used for RGBA will be different for all the graphics modes that use a different bit depth.