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(Bitmap_writePixels, 256, 256, false, 3) {
draw(SkCanvas * canvas)5 void draw(SkCanvas* canvas) {
6 std::vector<int32_t> srcPixels;
7 int width = image->width();
8 int height = image->height();
9 srcPixels.resize(height * width * 4);
10 SkPixmap pixmap(SkImageInfo::MakeN32Premul(width, height), (const void*) &srcPixels.front(),
11 width * 4);
12 image->readPixels(nullptr, pixmap, 0, 0);
13 canvas->scale(.5f, .5f);
14 width /= 4;
15 height /= 4;
16 for (int y = 0; y < 4; ++y) {
17 for (int x = 0; x < 4; ++x) {
18 SkBitmap bitmap;
19 bitmap.allocPixels(SkImageInfo::MakeN32Premul(width, height));
20 bitmap.writePixels(pixmap, -y * width, -x * height);
21 canvas->drawImage(bitmap.asImage(), x * width, y * height);
22 }
23 }
24 }
25 } // END FIDDLE
26