xref: /third_party/skia/docs/examples/Canvas_destructor.cpp (revision cb93a386)
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/skia/docs/examples/
1cb93a386Sopenharmony_ci// Copyright 2019 Google LLC.
2cb93a386Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3cb93a386Sopenharmony_ci#include "tools/fiddle/examples.h"
4cb93a386Sopenharmony_ci// HASH=b7bc91ff16c9b9351b2a127f35394b82
5cb93a386Sopenharmony_ciREG_FIDDLE(Canvas_destructor, 256, 256, false, 0) {
6cb93a386Sopenharmony_civoid draw(SkCanvas* canvas) {
7cb93a386Sopenharmony_ci    SkBitmap bitmap;
8cb93a386Sopenharmony_ci    bitmap.allocPixels(SkImageInfo::MakeN32Premul(200, 200));
9cb93a386Sopenharmony_ci    {
10cb93a386Sopenharmony_ci        SkCanvas offscreen(bitmap);
11cb93a386Sopenharmony_ci        SkPaint paint;
12cb93a386Sopenharmony_ci        SkFont font(nullptr, 100);
13cb93a386Sopenharmony_ci        offscreen.drawString("ABC", 20, 160, font, paint);
14cb93a386Sopenharmony_ci        SkRect layerBounds = SkRect::MakeXYWH(32, 32, 192, 192);
15cb93a386Sopenharmony_ci        offscreen.saveLayerAlpha(&layerBounds, 128);
16cb93a386Sopenharmony_ci        offscreen.clear(SK_ColorWHITE);
17cb93a386Sopenharmony_ci        offscreen.drawString("DEF", 20, 160, font, paint);
18cb93a386Sopenharmony_ci    }
19cb93a386Sopenharmony_ci    canvas->drawImage(bitmap.asImage(), 0, 0);
20cb93a386Sopenharmony_ci}
21cb93a386Sopenharmony_ci}  // END FIDDLE
22

Indexes created Thu Nov 07 10:32:03 CST 2024