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=cd203a3f9c5fb68272f21f302dd54fbc |
Hal Canary | a7181e7c | 2019-03-18 16:06:34 -0400 | [diff] [blame] | 5 | REG_FIDDLE(ImageInfo_makeWH, 256, 144, false, 3) { |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 6 | void draw(SkCanvas* canvas) { |
| 7 | SkImageInfo canvasImageInfo = canvas->imageInfo(); |
| 8 | SkRect canvasBounds = SkRect::Make(canvasImageInfo.bounds()); |
Mike Reed | ecdd979 | 2021-01-27 20:39:22 -0500 | [diff] [blame] | 9 | canvas->drawImageRect(image, SkRect::Make(source.bounds()), canvasBounds, SkSamplingOptions(), |
| 10 | nullptr, SkCanvas::kStrict_SrcRectConstraint); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 11 | SkImageInfo insetImageInfo = |
| 12 | canvasImageInfo.makeWH(canvasBounds.width() / 2, canvasBounds.height() / 2); |
| 13 | SkBitmap inset; |
| 14 | inset.allocPixels(insetImageInfo); |
| 15 | SkCanvas offscreen(inset); |
Mike Reed | ecdd979 | 2021-01-27 20:39:22 -0500 | [diff] [blame] | 16 | offscreen.drawImageRect(image, SkRect::Make(source.bounds()), SkRect::Make(inset.bounds()), |
| 17 | SkSamplingOptions(), nullptr, SkCanvas::kStrict_SrcRectConstraint); |
| 18 | canvas->drawImage(inset.asImage(), canvasBounds.width() / 4, canvasBounds.height() / 4); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 19 | } |
| 20 | } // END FIDDLE |