blob: 1f8a228dc76badfebedf636ba155c6af15cf3d57 [file] [log] [blame]
Hal Canary87515122019-03-15 14:22:51 -04001// 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.
Mike Kleinc0bd9f92019-04-23 12:05:21 -05003#include "tools/fiddle/examples.h"
Hal Canary87515122019-03-15 14:22:51 -04004// HASH=092739b4cd5d732a27c07ced8ef45f01
Hal Canarya7181e7c2019-03-18 16:06:34 -04005REG_FIDDLE(Bitmap_extractAlpha_2, 256, 160, false, 0) {
Hal Canary87515122019-03-15 14:22:51 -04006void 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