Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
write_text_to_png.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
14#include "include/core/SkFont.h"
22
23#include <cstdio>
24
25int main(int argc, char** argv) {
26 if (argc != 2) {
27 printf("Usage: %s <name.png>", argv[0]);
28 return 1;
29 }
30 SkFILEWStream output(argv[1]);
31 if (!output.isValid()) {
32 printf("Cannot open output file %s\n", argv[1]);
33 return 1;
34 }
36 SkCanvas* canvas = surface->getCanvas();
38 sk_sp<SkTypeface> face = mgr->matchFamilyStyle("Roboto", SkFontStyle());
39 if (!face) {
40 printf("Cannot open typeface\n");
41 return 1;
42 }
43 SkFont font(face, 14);
45 paint.setColor(SK_ColorGREEN);
46 canvas->clear(SK_ColorYELLOW);
47 canvas->drawString("Hello world!", 10, 25, font, paint);
48 SkPixmap pixmap;
49 if (surface->peekPixels(&pixmap)) {
50 if (!SkPngEncoder::Encode(&output, pixmap, {})) {
51 printf("Cannot write output\n");
52 return 1;
53 }
54 } else {
55 printf("Cannot readback on surface\n");
56 return 1;
57 }
58 return 0;
59}
@ kOpaque_SkAlphaType
pixel is opaque
Definition SkAlphaType.h:28
constexpr SkColor SK_ColorYELLOW
Definition SkColor.h:139
constexpr SkColor SK_ColorGREEN
Definition SkColor.h:131
SK_API sk_sp< SkFontMgr > SkFontMgr_New_FontConfig(FcConfig *fc)
void clear(SkColor color)
Definition SkCanvas.h:1199
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition SkCanvas.h:1803
const Paint & paint
VkSurfaceKHR surface
Definition main.cc:49
char ** argv
Definition library.h:9
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
Definition main.py:1
static SkImageInfo MakeN32(int width, int height, SkAlphaType at)