| 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(Canvas_const_SkBitmap_const_SkSurfaceProps, 256, 256, true, 0) { |
| 5 |
void draw(SkCanvas* ) { |
| 6 |
SkBitmap bitmap; |
| 7 |
// create a bitmap 5 wide and 11 high |
| 8 |
bitmap.allocPixels(SkImageInfo::MakeN32Premul(5, 11)); |
| 9 |
SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry)); |
| 10 |
canvas.clear(SK_ColorWHITE); // white is Unpremultiplied, in ARGB order |
| 11 |
SkPixmap pixmap; // provides guaranteed access to the drawn pixels |
| 12 |
if (!canvas.peekPixels(&pixmap)) { |
| 13 |
SkDebugf("peekPixels should never fail.\n"); |
| 14 |
} |
| 15 |
const SkPMColor* pixels = pixmap.addr32(); // points to top-left of bitmap |
| 16 |
SkPMColor pmWhite = pixels[0]; // the Premultiplied format may vary |
| 17 |
SkPaint paint; // by default, draws black, 12 point text |
| 18 |
SkFont font = SkFont(fontMgr->matchFamilyStyle(nullptr, {})); |
| 19 |
canvas.drawString("!", 1, 10, font, paint); // 1 char at baseline (1, 10) |
| 20 |
for (int y = 0; y < bitmap.height(); ++y) { |
| 21 |
for (int x = 0; x < bitmap.width(); ++x) { |
| 22 |
SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x'); |
| 23 |
} |
| 24 |
SkDebugf("\n"); |
| 25 |
} |
| 26 |
} |
| 27 |
} // END FIDDLE |