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. 3#include "tools/fiddle/examples.h" 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); 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->drawImage(bitmap.asImage(), 0, -offset.fY, SkSamplingOptions(), &paint); 27 canvas->drawImage(alpha.asImage(), 100 + offset.fX, 0, SkSamplingOptions(), &paint); 28} 29} // END FIDDLE 30