Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 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. |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 3 | #include "tools/fiddle/examples.h" |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 4 | // HASH=cd7543fa8c9f3cede46dc2d72eb8c4bd |
Hal Canary | a7181e7c | 2019-03-18 16:06:34 -0400 | [diff] [blame] | 5 | REG_FIDDLE(Bitmap_extractAlpha_3, 256, 128, false, 0) { |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 6 | void draw(SkCanvas* canvas) { |
| 7 | SkBitmap alpha, bitmap; |
| 8 | bitmap.allocN32Pixels(100, 100); |
| 9 | SkCanvas offscreen(bitmap); |
| 10 | offscreen.clear(0); |
| 11 | SkPaint paint; |
| 12 | paint.setAntiAlias(true); |
| 13 | paint.setColor(SK_ColorBLUE); |
| 14 | paint.setStyle(SkPaint::kStroke_Style); |
| 15 | paint.setStrokeWidth(20); |
| 16 | offscreen.drawCircle(50, 50, 39, paint); |
| 17 | offscreen.flush(); |
| 18 | paint.setMaskFilter(SkMaskFilter::MakeBlur(kOuter_SkBlurStyle, 3)); |
| 19 | SkIPoint offset; |
| 20 | bitmap.extractAlpha(&alpha, &paint, nullptr, &offset); |
| 21 | paint.setColor(SK_ColorRED); |
Mike Reed | b339d05 | 2021-01-28 11:20:41 -0500 | [diff] [blame] | 22 | canvas->drawImage(bitmap.asImage(), 0, -offset.fY, SkSamplingOptions(), &paint); |
| 23 | canvas->drawImage(alpha.asImage(), 100 + offset.fX, 0, SkSamplingOptions(), &paint); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 24 | } |
| 25 | } // END FIDDLE |