Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 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. |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 3 | #include "tools/fiddle/examples.h" |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 4 | // HASH=4f153cf1d0dbe1a95acf5badeec14dae |
Hal Canary | a7181e7c | 2019-03-18 16:06:34 -0400 | [diff] [blame] | 5 | REG_FIDDLE(Canvas_drawImageNine, 256, 128, false, 0) { |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 6 | void 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 Reed | dc607e3 | 2020-12-23 11:50:36 -0500 | [diff] [blame] | 24 | sk_sp<SkImage> image = bitmap.asImage(); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 25 | SkImage* imagePtr = image.get(); |
| 26 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
Mike Reed | 9911630 | 2021-01-25 11:37:10 -0500 | [diff] [blame] | 27 | canvas->drawImageNine(imagePtr, center, SkRect::MakeWH(dest, dest), |
| 28 | SkFilterMode::kNearest, nullptr); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 29 | canvas->translate(dest + 4, 0); |
| 30 | } |
| 31 | } |
| 32 | } // END FIDDLE |