2

Take #2066E100 (ARGB8888) as an example, preview the color in Android: enter image description here (dark green)

However, in iOS, the resulted color is like this: enter image description here (light yellow)

It seems to me that the alpha channel doesn't work the same way in iOS and Android. So my question is that is there a general scheme to convert argb color from Android to iOS?

I want to make iOS display the same color with Android's.

Edit: more images (this time I use #4066E100)

Android: enter image description here

iOS: enter image description here

Edit: add swift code

if let context = CGBitmapContextCreate(&colors, dim, dim, 8, 4 * dim, CGColorSpaceCreateDeviceRGB(), CGImageAlphaInfo.PremultipliedLast.rawValue | CGBitmapInfo.ByteOrderDefault.rawValue) {
        if let cgimage = CGBitmapContextCreateImage(context) {
            let uiimage = UIImage.init(CGImage: cgimage)
            return uiimage
        }
    }
Huang C.
  • 398
  • 6
  • 17
  • Use something like Sip or any other color picker to pick the rendered color on a mac, then use the color code for your iOS app. https://itunes.apple.com/us/app/sip/id507257563?mt=12 – Happiehappie Jul 18 '16 at 08:38
  • change ios to be the same as android – Zoe Jul 18 '16 at 08:39
  • 1
    Could there be a difference between that background where this color is being displayed in either platform? Behind a white background, the color should show as the light yellow - behind a black background, the color should appear dark green - this is due to the alpha channel – Gil Moshayof Jul 18 '16 at 08:39

1 Answers1

1

I doubt there's an actual difference between how ARGB colors are processed on either platform. It seems to me that the only difference here is the background on which they are being displayed.

A quick look at the color you supplied without the alpha channel shows a bright green color.

With 0x20 for the alpha channel, this makes the color almost transparent, and so the background color where this color is being displayed will have a strong influence on the overall color.

A black background would show that dark green you're seeing, and a white background would show that bright yellow you're seeing.

Have a look at the background color on each platform, and make sure they are the same on both. Then the colors should appear the same (different display color sharpness not withstanding).

Gil Moshayof
  • 16,633
  • 4
  • 47
  • 58
  • Thanks for the answer. It does make sense to me. However, when I do more experiments, the result is still incorrect. Could you check my edits in the questions again? – Huang C. Jul 18 '16 at 09:10
  • It looks like android is rendering correctly, and ios is adding a white background. How are you rendering this in ios? – Gil Moshayof Jul 18 '16 at 09:12
  • I have added swift code in another edit. I saved the argb colors as and UInt32 array named colors. – Huang C. Jul 18 '16 at 09:37
  • By the way, in iOS I represent the color in rgba format instead of argb to match the API call for creating the bitmap. – Huang C. Jul 18 '16 at 09:51
  • I'm afraid my swift skills are a bit rusty... you're creating UIImages, but are they being added to UIViews? If so, perhaps try setting the alpha on the view itself and removing the alpha component from the color? If that doesn't work, perhaps you should try opening a new question under the iOS tag on how to apply an alpha channel properly to UIImage – Gil Moshayof Jul 18 '16 at 10:23