I need to access a .png image file’s RGBA data. I found that reading a .png image using Firemonkey’s TBitmap.LoadFromFile changes the RGB values. They get premultiplied by the alpha value, thus losing the original RGB values whenever alpha is not 255.
In Windows I traced it to TBitmapCodecWIC.DecodeFrame in FMX.Canvas.D2D where it uses the GUID_WICPixelFormat32bppPBGRA pixel format, which according to WIC docs implies D2D1_ALPHA_MODE_PREMULTIPLIED.
Investigating further, I understand I can approximately recover the lost RGB values by doing an “UnPreMultiplyAlpha” which effectively divides the RGB values by the alpha value again. This works, visually, but as you can imagine is pretty lossy especially for pixels with low alpha and/or low RGB values.
Is there a way to tell TBitmap.LoadFromFile to retain the original RGBA values?