Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
skia
docs
examples
blur_alpha_img.cpp
Go to the documentation of this file.
1
// Copyright 2020 Google LLC.
2
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3
#include "
tools/fiddle/examples.h
"
4
REG_FIDDLE
(blur_alpha_img, 256, 256,
false
, 0) {
5
sk_sp<SkImage>
foo() {
6
int
w
= 240,
h
= 240;
7
SkScalar
scale
= 10.0f;
8
SkPath
path;
9
static
const
int8_t pts[] = {2, 2, 1, 3, 0, 3, 2, 1, 3, 1, 4, 0, 4, 1,
10
5, 1, 4, 2, 4, 3, 2, 5, 2, 4, 3, 3, 2, 3};
11
path.moveTo(2 *
scale
, 3 *
scale
);
12
for
(
size_t
i = 0; i <
sizeof
(pts) /
sizeof
(pts[0]); i += 2) {
13
path.lineTo(pts[i] *
scale
, pts[i + 1] *
scale
);
14
}
15
path.close();
16
SkMatrix
matrix =
SkMatrix::Scale
(4 *
scale
, 4 *
scale
);
17
SkPaint
paint
;
18
paint
.setPathEffect(
SkPath2DPathEffect::Make
(matrix, path));
19
paint
.setAntiAlias(
true
);
20
SkRect
bounds{-4 *
scale
, -4 *
scale
, (float)
w
, (
float
)
h
};
21
SkBitmap
bm;
22
bm.
allocPixels
(
SkImageInfo::MakeA8
(
w
,
h
));
23
SkCanvas
c(bm);
24
c.
clear
(0);
25
c.
drawRect
(bounds,
paint
);
26
return
bm.
asImage
();
27
}
28
29
void
draw
(
SkCanvas
* canvas) {
30
auto
a8img = foo();
31
SkPaint
paint
;
32
paint
.setMaskFilter(
SkMaskFilter::MakeBlur
(
kNormal_SkBlurStyle
, 2.0f, 0));
33
paint
.setColor(0xFF008000);
34
canvas->
drawImage
(a8img, 8, 8,
SkSamplingOptions
(), &
paint
);
35
}
36
}
// END FIDDLE
kNormal_SkBlurStyle
@ kNormal_SkBlurStyle
fuzzy inside and outside
Definition
SkBlurTypes.h:12
draw
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition
aaclip.cpp:27
SkBitmap
Definition
SkBitmap.h:59
SkBitmap::allocPixels
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition
SkBitmap.cpp:258
SkBitmap::asImage
sk_sp< SkImage > asImage() const
Definition
SkBitmap.cpp:645
SkCanvas
Definition
SkCanvas.h:106
SkCanvas::drawRect
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition
SkCanvas.cpp:1997
SkCanvas::clear
void clear(SkColor color)
Definition
SkCanvas.h:1199
SkCanvas::drawImage
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition
SkCanvas.h:1528
SkMaskFilter::MakeBlur
static sk_sp< SkMaskFilter > MakeBlur(SkBlurStyle style, SkScalar sigma, bool respectCTM=true)
Definition
SkBlurMaskFilterImpl.cpp:535
SkMatrix
Definition
SkMatrix.h:54
SkMatrix::Scale
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition
SkMatrix.h:75
SkPaint
Definition
SkPaint.h:44
SkPath2DPathEffect::Make
static sk_sp< SkPathEffect > Make(const SkMatrix &matrix, const SkPath &path)
Definition
Sk2DPathEffect.cpp:213
SkPath
Definition
SkPath.h:59
sk_sp
Definition
SkRefCnt.h:220
paint
const Paint & paint
Definition
color_source.cc:38
examples.h
REG_FIDDLE
#define REG_FIDDLE(NAME, W, H, TEXT, I)
Definition
examples.h:60
SkScalar
float SkScalar
Definition
extension.cpp:12
w
SkScalar w
Definition
pictureshadertile.cpp:30
h
SkScalar h
Definition
pictureshadertile.cpp:30
scale
const Scalar scale
Definition
stroke_path_geometry.cc:253
SkImageInfo::MakeA8
static SkImageInfo MakeA8(int width, int height)
Definition
SkImageInfo.cpp:173
SkRect
Definition
extension.cpp:13
SkSamplingOptions
Definition
SkSamplingOptions.h:58
Generated on Fri Apr 26 2024 06:15:32 for Flutter Engine by
1.9.8