1cb93a386Sopenharmony_ci// Copyright 2019 Google LLC.
2cb93a386Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3cb93a386Sopenharmony_ci#include "tools/fiddle/examples.h"
4cb93a386Sopenharmony_ci// HASH=d597d9af8d17fd93e634dd12017058e2
5cb93a386Sopenharmony_ciREG_FIDDLE(Canvas_drawImageNine_2, 256, 128, false, 0) {
6cb93a386Sopenharmony_civoid draw(SkCanvas* canvas) {
7cb93a386Sopenharmony_ci    SkIRect center = { 20, 10, 50, 40 };
8cb93a386Sopenharmony_ci    SkBitmap bitmap;
9cb93a386Sopenharmony_ci    bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60));
10cb93a386Sopenharmony_ci    SkCanvas bitCanvas(bitmap);
11cb93a386Sopenharmony_ci    SkPaint paint;
12cb93a386Sopenharmony_ci    SkColor gray = 0xFF000000;
13cb93a386Sopenharmony_ci    int left = 0;
14cb93a386Sopenharmony_ci    for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) {
15cb93a386Sopenharmony_ci        int top = 0;
16cb93a386Sopenharmony_ci        for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) {
17cb93a386Sopenharmony_ci            paint.setColor(gray);
18cb93a386Sopenharmony_ci            bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint);
19cb93a386Sopenharmony_ci            gray += 0x001f1f1f;
20cb93a386Sopenharmony_ci            top = bottom;
21cb93a386Sopenharmony_ci        }
22cb93a386Sopenharmony_ci        left = right;
23cb93a386Sopenharmony_ci    }
24cb93a386Sopenharmony_ci    sk_sp<SkImage> image = bitmap.asImage();
25cb93a386Sopenharmony_ci    for (auto dest: { 20, 30, 40, 60, 90 } ) {
26cb93a386Sopenharmony_ci        canvas->drawImageNine(image.get(), center, SkRect::MakeWH(dest, 110 - dest),
27cb93a386Sopenharmony_ci                              SkFilterMode::kNearest, nullptr);
28cb93a386Sopenharmony_ci        canvas->translate(dest + 4, 0);
29cb93a386Sopenharmony_ci    }
30cb93a386Sopenharmony_ci}
31cb93a386Sopenharmony_ci}  // END FIDDLE
32