blob: 14bef1b4631f21b7ce7706a0a0d4ba45f09ec02f [file] [log] [blame]
Hal Canary87515122019-03-15 14:22:51 -04001// 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.
Mike Kleinc0bd9f92019-04-23 12:05:21 -05003#include "tools/fiddle/examples.h"
Hal Canary87515122019-03-15 14:22:51 -04004// HASH=102d014d7f753db2a9b9ee08893aaf11
Hal Canarya7181e7c2019-03-18 16:06:34 -04005REG_FIDDLE(Canvas_readPixels_a, 64, 64, false, 0) {
Hal Canary87515122019-03-15 14:22:51 -04006void draw(SkCanvas* canvas) {
7 canvas->clear(SK_ColorBLUE);
8 SkPaint paint;
9 canvas->drawCircle(32, 32, 28, paint);
10 SkImageInfo info = SkImageInfo::Make(64, 64, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
11 sk_sp<SkData> data(SkData::MakeUninitialized(info.minRowBytes() * info.height()));
12 sk_bzero(data->writable_data(), info.minRowBytes() * info.height());
13 for (int x : { 32, -32 } ) {
14 for (int y : { 32, -32 } ) {
15 canvas->readPixels(info, data->writable_data(), info.minRowBytes(), x, y);
16 }
17 }
18 sk_sp<SkImage> image = SkImage::MakeRasterData(info, data, info.minRowBytes());
19 canvas->drawImage(image, 0, 0);
20}
21} // END FIDDLE