1 // Copyright 2019 Google LLC.
2 // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3 #include "tools/fiddle/examples.h"
4 REG_FIDDLE(Image_DeferredFromPicture, 256, 256, false, 0) {
draw(SkCanvas * canvas)5 void draw(SkCanvas* canvas) {
6 SkPaint paint;
7 SkPictureRecorder recorder;
8 SkCanvas* recordingCanvas = recorder.beginRecording(50, 50);
9 for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) {
10 paint.setColor(color);
11 recordingCanvas->drawRect({10, 10, 30, 40}, paint);
12 recordingCanvas->translate(10, 10);
13 recordingCanvas->scale(1.2f, 1.4f);
14 }
15 sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture();
16 int x = 0, y = 0;
17 for (auto alpha : { 70, 140, 210 } ) {
18 paint.setAlpha(alpha);
19 auto srgbColorSpace = SkColorSpace::MakeSRGB();
20 sk_sp<SkImage> image = SkImages::DeferredFromPicture(
21 playback, {50, 50}, nullptr, &paint, SkImages::BitDepth::kU8, srgbColorSpace);
22 canvas->drawImage(image, x, y);
23 x += 70; y += 70;
24 }
25 }
26 } // END FIDDLE
27