Flutter Engine
The Flutter Engine
Canvas_drawImageRect.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_drawImageRect, 256, 64, false, 0) {
5void draw(SkCanvas* canvas) {
6 uint32_t pixels[][4] = {
7 { 0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000 },
8 { 0xFFFF0000, 0xFF000000, 0xFFFFFFFF, 0xFFFF0000 },
9 { 0xFFFF0000, 0xFFFFFFFF, 0xFF000000, 0xFFFF0000 },
10 { 0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000 } };
11 SkBitmap redBorder;
13 (void*) pixels, sizeof(pixels[0]));
14 sk_sp<SkImage> image = redBorder.asImage();
16 for (auto constraint : {
20 canvas->drawImageRect(image.get(), SkRect::MakeLTRB(1, 1, 3, 3),
21 SkRect::MakeLTRB(16, 16, 48, 48), sampling, nullptr, constraint);
23 canvas->translate(80, 0);
24 }
25}
26} // END FIDDLE
REG_FIDDLE(Canvas_drawImageRect, 256, 64, false, 0)
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
bool installPixels(const SkImageInfo &info, void *pixels, size_t rowBytes, void(*releaseProc)(void *addr, void *context), void *context)
Definition: SkBitmap.cpp:323
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
@ kStrict_SrcRectConstraint
sample only inside bounds; slower
Definition: SkCanvas.h:1542
@ kFast_SrcRectConstraint
sample outside bounds; faster
Definition: SkCanvas.h:1543
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
Definition: SkCanvas.cpp:2333
T * get() const
Definition: SkRefCnt.h:303
sk_sp< const SkImage > image
Definition: SkRecords.h:269
SkSamplingOptions sampling
Definition: SkRecords.h:337
SkSamplingOptions(SkFilterMode::kLinear))
static SkImageInfo MakeN32Premul(int width, int height)
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646