Created
January 30, 2022 17:23
-
-
Save piusayowale/0078d0b8b7e65fc11b2b05c0d032310e to your computer and use it in GitHub Desktop.
Skia write to bitmap example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <skia/core/SkCanvas.h> | |
#include <skia/core/SkBitmap.h> | |
#include <skia/codec/SkCodec.h> | |
#include <skia/core/SkPath.h> | |
#include <skia/core/SkColor.h> | |
#include <skia/encode/SkPngEncoder.h> | |
#include <skia/core/SkStream.h> | |
#include <skia/core/SkImageEncoder.h> | |
#include <skia/core/SkData.h> | |
#include <skia/core/SkRefCnt.h> | |
#include <skia/core/SkFont.h> | |
#include <skia/core/SkPaint.h> | |
#include <skia/core/SkTypeface.h> | |
#include <fstream> | |
int main() | |
{ | |
SkBitmap bitmap{}; | |
bitmap.allocN32Pixels(600, 600); | |
SkCanvas canvas{bitmap}; | |
SkColor color(SkColors::kBlack.toSkColor()); | |
canvas.drawColor(color); | |
SkPaint paint; | |
SkColor textcolor(0xFFF23FFF); | |
paint.setColor(textcolor); | |
SkFont font; | |
font.setSize(20); | |
canvas.drawString("Pius Ayowale", 250, 200, font, paint); | |
auto data = SkEncodeBitmap(bitmap, SkEncodedImageFormat::kPNG, 80); | |
std::ofstream file("img.png", std::ios_base::out | std::ios_base::binary); | |
file.write((const char *)data.get()->bytes(), data->size()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment