blob: aadc9405e0bd492c16c8f2d5fe2201ff18f20637 [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=cd203a3f9c5fb68272f21f302dd54fbc
Hal Canarya7181e7c2019-03-18 16:06:34 -04005REG_FIDDLE(ImageInfo_makeWH, 256, 144, false, 3) {
Hal Canary87515122019-03-15 14:22:51 -04006void draw(SkCanvas* canvas) {
7 SkImageInfo canvasImageInfo = canvas->imageInfo();
8 SkRect canvasBounds = SkRect::Make(canvasImageInfo.bounds());
Mike Reedecdd9792021-01-27 20:39:22 -05009 canvas->drawImageRect(image, SkRect::Make(source.bounds()), canvasBounds, SkSamplingOptions(),
10 nullptr, SkCanvas::kStrict_SrcRectConstraint);
Hal Canary87515122019-03-15 14:22:51 -040011 SkImageInfo insetImageInfo =
12 canvasImageInfo.makeWH(canvasBounds.width() / 2, canvasBounds.height() / 2);
13 SkBitmap inset;
14 inset.allocPixels(insetImageInfo);
15 SkCanvas offscreen(inset);
Mike Reedecdd9792021-01-27 20:39:22 -050016 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 Canary87515122019-03-15 14:22:51 -040019}
20} // END FIDDLE