Flutter Engine
The Flutter Engine
Functions
Bitmap_extractAlpha_2.cpp File Reference
#include "tools/fiddle/examples.h"

Go to the source code of this file.

Functions

 REG_FIDDLE (Bitmap_extractAlpha_2, 256, 160, false, 0)
 

Function Documentation

◆ REG_FIDDLE()

REG_FIDDLE ( Bitmap_extractAlpha_2  ,
256  ,
160  ,
false  ,
 
)

Definition at line 4 of file Bitmap_extractAlpha_2.cpp.

4 {
5void draw(SkCanvas* canvas) {
6 auto radiusToSigma = [](SkScalar radius) -> SkScalar {
7 static const SkScalar kBLUR_SIGMA_SCALE = 0.57735f;
8 return radius > 0 ? kBLUR_SIGMA_SCALE * radius + 0.5f : 0.0f;
9 };
10 SkBitmap alpha, bitmap;
11 bitmap.allocN32Pixels(100, 100);
12 SkCanvas offscreen(bitmap);
13 offscreen.clear(0);
15 paint.setAntiAlias(true);
16 paint.setColor(SK_ColorBLUE);
18 paint.setStrokeWidth(20);
19 offscreen.drawCircle(50, 50, 39, paint);
20 paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, radiusToSigma(25)));
22 bitmap.extractAlpha(&alpha, &paint, &offset);
23 paint.setColor(SK_ColorRED);
24 canvas->drawImage(bitmap.asImage(), 0, -offset.fY, SkSamplingOptions(), &paint);
25 canvas->drawImage(alpha.asImage(), 100 + offset.fX, 0, SkSamplingOptions(), &paint);
26}
27} // END FIDDLE
static const SkScalar kBLUR_SIGMA_SCALE
Definition: SkBlurMask.cpp:37
@ 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 drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
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
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
Definition: bitmap.py:1
SeparatedVector2 offset