SkBitmap bitmap; bitmap.setInfo({256, 256}, kRGB_8888_SkColorType, kPremul_SkAlphaType); if (bitmap.allocPixels()) { // Do something with the allocated bitmap }
SkBitmap bitmap; bitmap.setInfo({640, 480}, kRGBA_8888_SkColorType, kUnpremul_SkAlphaType); if (bitmap.allocPixels()) { uint32_t* pixels = bitmap.getPixels(); // Initialize pixels with some data for (int i = 0; i < bitmap.width() * bitmap.height(); i++) { pixels[i] = 0xFF000000; // Set all pixels to opaque black } }In this example, we create a bitmap with dimensions of 640x480 pixels and RGBA color format with unpremultiplied alpha. We then allocate memory for the bitmap and retrieve a pointer to its pixel data using the getPixels method. We can then initialize the pixels with some data, in this case setting all pixels to opaque black. Package library: Skia Graphics Engine