Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
Canvas_drawImageNine.cpp File Reference
#include "tools/fiddle/examples.h"

Go to the source code of this file.

Functions

 REG_FIDDLE (Canvas_drawImageNine, 256, 128, false, 0)
 

Function Documentation

◆ REG_FIDDLE()

REG_FIDDLE ( Canvas_drawImageNine  ,
256  ,
128  ,
false  ,
 
)

Definition at line 5 of file Canvas_drawImageNine.cpp.

5 {
6void draw(SkCanvas* canvas) {
7 SkIRect center = { 20, 10, 50, 40 };
9 bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60));
10 SkCanvas bitCanvas(bitmap);
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 }
24 sk_sp<SkImage> image = bitmap.asImage();
25 SkImage* imagePtr = image.get();
26 for (auto dest: { 20, 30, 40, 60, 90 } ) {
27 canvas->drawImageNine(imagePtr, center, SkRect::MakeWH(dest, dest),
28 SkFilterMode::kNearest, nullptr);
29 canvas->translate(dest + 4, 0);
30 }
31}
32} // END FIDDLE
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)
void drawImageNine(const SkImage *image, const SkIRect &center, const SkRect &dst, SkFilterMode filter, const SkPaint *paint=nullptr)
T * get() const
Definition SkRefCnt.h:303
const Paint & paint
sk_sp< SkImage > image
Definition examples.cpp:29
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