Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Bitmap_extractAlpha_2.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=092739b4cd5d732a27c07ced8ef45f01
5REG_FIDDLE(Bitmap_extractAlpha_2, 256, 160, false, 0) {
6void draw(SkCanvas* canvas) {
7 auto radiusToSigma = [](SkScalar radius) -> SkScalar {
8 static const SkScalar kBLUR_SIGMA_SCALE = 0.57735f;
9 return radius > 0 ? kBLUR_SIGMA_SCALE * radius + 0.5f : 0.0f;
10 };
11 SkBitmap alpha, bitmap;
12 bitmap.allocN32Pixels(100, 100);
13 SkCanvas offscreen(bitmap);
14 offscreen.clear(0);
16 paint.setAntiAlias(true);
17 paint.setColor(SK_ColorBLUE);
19 paint.setStrokeWidth(20);
20 offscreen.drawCircle(50, 50, 39, paint);
21 paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, radiusToSigma(25)));
23 bitmap.extractAlpha(&alpha, &paint, &offset);
24 paint.setColor(SK_ColorRED);
25 canvas->drawImage(bitmap.asImage(), 0, -offset.fY, SkSamplingOptions(), &paint);
26 canvas->drawImage(alpha.asImage(), 100 + offset.fX, 0, SkSamplingOptions(), &paint);
27}
28} // END FIDDLE
static const SkScalar kBLUR_SIGMA_SCALE
@ kNormal_SkBlurStyle
fuzzy inside and outside
Definition SkBlurTypes.h:12
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition aaclip.cpp:27
sk_sp< SkImage > asImage() const
Definition SkBitmap.cpp:645
void clear(SkColor color)
Definition SkCanvas.h:1199
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition SkCanvas.h:1528
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
static sk_sp< SkMaskFilter > MakeBlur(SkBlurStyle style, SkScalar sigma, bool respectCTM=true)
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
const Paint & paint
#define REG_FIDDLE(NAME, W, H, TEXT, I)
Definition examples.h:60
float SkScalar
Definition extension.cpp:12
Point offset