Flutter Engine
The Flutter Engine
Canvas_drawImageNine.cpp
Go to the documentation of this file.
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.
4REG_FIDDLE(Canvas_drawImageNine, 256, 128, false, 0) {
5void draw(SkCanvas* canvas) {
6 SkIRect center = { 20, 10, 50, 40 };
8 bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60));
9 SkCanvas bitCanvas(bitmap);
11 SkColor gray = 0xFF000000;
12 int left = 0;
13 for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) {
14 int top = 0;
15 for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) {
16 paint.setColor(gray);
17 bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint);
18 gray += 0x001f1f1f;
19 top = bottom;
20 }
21 left = right;
22 }
23 sk_sp<SkImage> image = bitmap.asImage();
24 SkImage* imagePtr = image.get();
25 for (auto dest: { 20, 30, 40, 60, 90 } ) {
26 canvas->drawImageNine(imagePtr, center, SkRect::MakeWH(dest, dest),
27 SkFilterMode::kNearest, nullptr);
28 canvas->translate(dest + 4, 0);
29 }
30}
31} // END FIDDLE
REG_FIDDLE(Canvas_drawImageNine, 256, 128, false, 0)
uint32_t SkColor
Definition: SkColor.h:37
static bool left(const SkPoint &p0, const SkPoint &p1)
static bool right(const SkPoint &p0, const SkPoint &p1)
static SkScalar center(float pos0, float pos1)
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawImageNine(const SkImage *image, const SkIRect &center, const SkRect &dst, SkFilterMode filter, const SkPaint *paint=nullptr)
Definition: SkCanvas.cpp:1769
void drawIRect(const SkIRect &rect, const SkPaint &paint)
Definition: SkCanvas.h:1358
T * get() const
Definition: SkRefCnt.h:303
const Paint & paint
Definition: color_source.cc:38
sk_sp< const SkImage > image
Definition: SkRecords.h:269
Definition: bitmap.py:1
dest
Definition: zip.py:79
Definition: SkRect.h:32
static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
Definition: SkRect.h:91
static SkImageInfo MakeN32Premul(int width, int height)
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609