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 // HASH=22e7ce79ab2fe94252d23319f2258127
5 REG_FIDDLE(Image_MakeRasterData, 256, 256, false, 3) {
draw(SkCanvas * canvas)6 void draw(SkCanvas* canvas) {
7 size_t rowBytes = image->width() * SkColorTypeBytesPerPixel(kRGBA_8888_SkColorType);
8 sk_sp<SkData> data = SkData::MakeUninitialized(rowBytes * image->height());
9 SkImageInfo dstInfo = SkImageInfo::MakeN32(image->width(), image->height(),
10 kPremul_SkAlphaType);
11 image->readPixels(nullptr, dstInfo, data->writable_data(), rowBytes, 0, 0, SkImage::kAllow_CachingHint);
12 sk_sp<SkImage> raw = SkImage::MakeRasterData(dstInfo.makeColorType(kRGBA_8888_SkColorType),
13 data, rowBytes);
14 canvas->drawImage(image, 0, 0);
15 canvas->drawImage(raw.get(), 128, 0);
16 }
17 } // END FIDDLE
18