blob: 5932d2a6735d83d3e5ac7ccdb6b1763557707b49 [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=d597d9af8d17fd93e634dd12017058e2
Hal Canarya7181e7c2019-03-18 16:06:34 -04005REG_FIDDLE(Canvas_drawImageNine_2, 256, 128, false, 0) {
Hal Canary87515122019-03-15 14:22:51 -04006void draw(SkCanvas* canvas) {
7 SkIRect center = { 20, 10, 50, 40 };
8 SkBitmap bitmap;
9 bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60));
10 SkCanvas bitCanvas(bitmap);
11 SkPaint paint;
12 SkColor gray = 0xFF000000;
13 int left = 0;
14 for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) {
15 int top = 0;
16 for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) {
17 paint.setColor(gray);
18 bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint);
19 gray += 0x001f1f1f;
20 top = bottom;
21 }
22 left = right;
23 }
Mike Reeddc607e32020-12-23 11:50:36 -050024 sk_sp<SkImage> image = bitmap.asImage();
Hal Canary87515122019-03-15 14:22:51 -040025 for (auto dest: { 20, 30, 40, 60, 90 } ) {
Mike Reed99116302021-01-25 11:37:10 -050026 canvas->drawImageNine(image.get(), center, SkRect::MakeWH(dest, 110 - dest),
27 SkFilterMode::kNearest, nullptr);
Hal Canary87515122019-03-15 14:22:51 -040028 canvas->translate(dest + 4, 0);
29 }
30}
31} // END FIDDLE