RGB/BGR differences between Android and iOS #196
whispercomputersolutions
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
First off, I Love this project. Allows me to add ellipses, rectangles and arrows to photos on mobile devices.
Maybe I'm missing something simple, but it seems I had to do the following in my FMX app.
I chose yellow to draw these layers. But on Android, the red and blue are backwards for the pen color selection, but not on iOS. To correct on Android, I had to conditionally compile and then when setting a pen color in the Draw function I use this function:
function PlatformColor(pColor: TColor32): TColor32; begin {$ifdef Android} Result := RGBtoBGR(pColor); {$else} Result := pColor; {$endif} end;Next issue: When loading a jpg image stream into a bitmap on Android, the image colors are fine. Bit when loading on iOS the red and blue are swapped. In this case for iOS only, I had to traverse the bitmap image to swap red and blue:
procedure ConvertBitmapToABGR(var ABitmap: TBitmap); var Data: TBitmapData; begin // Map the bitmap memory for read-only access if ABitmap.Map(TMapAccess.Read, Data) then try for var Y := 0 to ABitmap.Height - 1 do begin for var X := 0 to ABitmap.Width - 1 do begin // FMX native 32-bit color (Alpha, Red, Green, Blue depending on platform) var ScanLine := PAlphaColorArray(Data.GetScanline(Y)); ScanLine[X] := RGBtoBGR(ScanLine[X]); end; end; finally ABitmap.Unmap(Data); end; end;Did I miss something?
Eric
All reactions