Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Pixmap_readPixels.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.
4// HASH=df4e355c4845350daede833b4fd21ec1
5REG_FIDDLE(Pixmap_readPixels, 256, 128, false, 0) {
6void draw(SkCanvas* canvas) {
7 std::vector<int32_t> pixels;
8 const int width = 256;
9 const int height = 64;
10 pixels.resize(height * width * 4);
12 SkPixmap srcPixmap(srcInfo, (const void*) &pixels.front(), width * 4);
13 SkColor gradColors[] = { 0xFFAA3300, 0x7F881122 };
14 SkPoint gradPoints[] = { { 0, 0 }, { 256, 0 } };
16 paint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
17 std::size(gradColors), SkTileMode::kClamp));
19 bitmap.installPixels(srcPixmap);
20 SkCanvas srcCanvas(bitmap);
22 canvas->drawImage(bitmap.asImage(), 0, 0);
23 std::vector<int32_t> dstPixels;
24 dstPixels.resize(height * width * 2);
26 srcPixmap.readPixels(dstInfo, &dstPixels.front(), width * 2);
27 SkPixmap dstPixmap(dstInfo, &dstPixels.front(), width * 2);
28 bitmap.installPixels(dstPixmap);
29 canvas->drawImage(bitmap.asImage(), 0, 128);
30}
31} // END FIDDLE
@ kARGB_4444_SkColorType
pixel with 4 bits for alpha, red, green, blue; in 16-bit word
Definition SkColorType.h:23
uint32_t SkColor
Definition SkColor.h:37
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition aaclip.cpp:27
void drawRect(const SkRect &rect, const SkPaint &paint)
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition SkCanvas.h:1528
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
bool readPixels(const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes) const
Definition SkPixmap.h:592
const Paint & paint
#define REG_FIDDLE(NAME, W, H, TEXT, I)
Definition examples.h:60
int32_t height
int32_t width
static SkImageInfo MakeN32Premul(int width, int height)
SkImageInfo makeColorType(SkColorType newColorType) const
static constexpr SkRect MakeWH(float w, float h)
Definition SkRect.h:609