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_peekPixels, 256, 256, true, 0) {
draw(SkCanvas * canvas)5 void draw(SkCanvas* canvas) {
6 SkBitmap bitmap;
7 bitmap.allocPixels(SkImageInfo::MakeN32Premul(6, 11));
8 SkCanvas offscreen(bitmap);
9 offscreen.clear(SK_ColorWHITE);
10 SkPaint paint;
11 SkFont font = SkFont(fontMgr->matchFamilyStyle(nullptr, {}));
12 offscreen.drawString("?", 0, 10, font, paint);
13 SkPixmap pixmap;
14 if (bitmap.peekPixels(&pixmap)) {
15 const SkPMColor* pixels = pixmap.addr32();
16 SkPMColor pmWhite = pixels[0];
17 for (int y = 0; y < bitmap.height(); ++y) {
18 for (int x = 0; x < bitmap.width(); ++x) {
19 SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x');
20 }
21 SkDebugf("\n");
22 }
23 }
24 }
25 } // END FIDDLE
26