blob: a57ffc0b5f7c7c1489cd05cc89187635c82c9433 [file] [log] [blame]
Hal Canary83c2f702019-03-07 14:53:03 -05001// 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.
3#include "fiddle/examples.h"
4// HASH=092739b4cd5d732a27c07ced8ef45f01
5REG_FIDDLE(Bitmap_075, 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);
15 SkPaint paint;
16 paint.setAntiAlias(true);
17 paint.setColor(SK_ColorBLUE);
18 paint.setStyle(SkPaint::kStroke_Style);
19 paint.setStrokeWidth(20);
20 offscreen.drawCircle(50, 50, 39, paint);
21 offscreen.flush();
22 paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, radiusToSigma(25)));
23 SkIPoint offset;
24 bitmap.extractAlpha(&alpha, &paint, &offset);
25 paint.setColor(SK_ColorRED);
26 canvas->drawBitmap(bitmap, 0, -offset.fY, &paint);
27 canvas->drawBitmap(alpha, 100 + offset.fX, 0, &paint);
28}
29} // END FIDDLE