Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
write_text_to_png.cpp File Reference
#include "include/core/SkAlphaType.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkTypeface.h"
#include "include/core/SkFont.h"
#include "include/core/SkFontStyle.h"
#include "include/core/SkFontMgr.h"
#include "include/core/SkPixmap.h"
#include "include/core/SkSurface.h"
#include "include/core/SkStream.h"
#include "include/encode/SkPngEncoder.h"
#include "include/ports/SkFontMgr_fontconfig.h"
#include <cstdio>

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 25 of file write_text_to_png.cpp.

25 {
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
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
std::string printf(const char *fmt,...) SK_PRINTF_LIKE(1
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
font
Font Metadata and Metrics.
static SkImageInfo MakeN32(int width, int height, SkAlphaType at)