Skia SKBitmap.GetPixel returns a different color

Sebastian 1 Reputation point
2021-03-24T12:45:36.91+00:00

I have a very basic use case where I want to count the colors used on an image so I am loading the image on a SKBitmap and looping through getting each pixel color and counting in a bucket.

I get the same amount of colors the original image has (32 colors) but unfortunately I can see that the RGBA colors returned don't seem to match the colors in the image palette. The image renders just fine on a SKCanvasView but as an example, the yellow color in the sample image I'm providing comes back as a pinkish color.

Any ideas what I am missing here? Is there a further conversion I need to make on the pixel color to get the real color?

81186-1958358.png

Code snippet:

var bitmap = SKBitmap.Decode(fileStream);  
  
for (int row = 0; row < bitmap.Height; row++)  
for (int col = 0; col < bitmap.Width; col++)  
{  
    var pixelColor = bitmap.GetPixel(col, row); <-- this is not the right color  
}  
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,295 questions
{count} votes