Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Bitmap_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=b2cbbbbcffb618865d8aae3bc04b2a62
5REG_FIDDLE(Bitmap_readPixels, 256, 128, false, 0) {
6void draw(SkCanvas* canvas) {
7 const int width = 256;
8 const int height = 64;
10 SkColor gradColors[] = { 0xFFAA3300, 0x7F881122 };
11 SkPoint gradPoints[] = { { 0, 0 }, { 256, 0 } };
13 paint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
14 std::size(gradColors), SkTileMode::kClamp));
16 bitmap.allocPixels(srcInfo);
17 SkCanvas srcCanvas(bitmap);
19 canvas->drawImage(bitmap.asImage(), 0, 0);
21 std::vector<int16_t> dstPixels;
22 dstPixels.resize(height * width);
23 bitmap.readPixels(dstInfo, &dstPixels.front(), width * 2, 0, 0);
24 SkPixmap dstPixmap(dstInfo, &dstPixels.front(), width * 2);
25 bitmap.installPixels(dstPixmap);
26 canvas->drawImage(bitmap.asImage(), 0, 64);
27}
28} // 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)
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