SkBitmap bitmap; // Load the bitmap image from a file or create it // ... auto colorTable = bitmap.getColorTable(); if (colorTable) { // Get the number of colors in the color table int numColors = colorTable->count(); // Print the RGB values of each color in the color table for (int i = 0; i < numColors; i++) { SkPMColor color = colorTable->operator[](i); SkColor rgbColor = SkPmColorToColor(color); int r, g, b; SkColorGetRGB(rgbColor, &r, &g, &b); std::cout << "Color " << i << ": R=" << r << ", G=" << g << ", B=" << b << std::endl; } }
SkBitmap bitmap; // Create an indexed color bitmap with a color table // ... auto colorTable = bitmap.getColorTable(); if (colorTable) { // Modify the first color in the color table SkPMColor color = colorTable->operator[](0); color = SkPremultiplyARGB(255, 0, 0, 255); // Blue color colorTable->operator[](0) = color; // Change the bitmap pixels to use the new color table bitmap.notifyPixelsChanged(); }This example creates an indexed color bitmap with a color table and modifies the first color in the color table to be blue. It then updates the bitmap pixels to use the new color table. This code has been written using the Skia package library.