Options
These globals are now defined:
double duration; // The requested duration of the animation. double frame; // A value in [0, 1] of where we are in the animation.
This global is now defined:
GrBackendRenderTarget backEndRenderTarget;
GrBackendTexture backEndTextureRenderTarget;
Optional source image
These globals are now defined:
SkBitmap source; sk_sp<SkImage> image; GrBackendTexture backEndTexture; // GPU Only.
Note:
Adding comments with SK_FOLD_START and SK_FOLD_END creates foldable code
blocks.
These blocks will be folded by default and are useful for highlighting specific lines of code.
You can also use the keyboard shortcuts Ctrl+S and Ctrl+E in the code editor to set them.
These blocks will be folded by default and are useful for highlighting specific lines of code.
You can also use the keyboard shortcuts Ctrl+S and Ctrl+E in the code editor to set them.
xxxxxxxxxx
54
// purplestamp
// Whether to use a separate bitmap (with a color type) at all.
bool drawWithRasterImage = true;
// This works with either kN32_SkColorType or kAlpha_8_SkColorType.
// Applies only if drawWithRasterImage is true.
SkColorType colorType = kN32_SkColorType;
void drawStamp(SkCanvas* canvas, int size) {
canvas->save();
canvas->clipRect(SkRect::MakeWH(size, size), SkClipOp::kIntersect, true);
canvas->clear(0x3F000000 /* translucent black */);
SkPaint paint;
paint.setAntiAlias(true);
paint.setColor(SK_ColorBLACK);
canvas->drawRRect(
SkRRect::MakeOval(SkRect::MakeXYWH(size / 4, size / 4, size / 2, size / 2)), paint);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(20);
canvas->drawRect(SkRect::MakeWH(size, size), paint);
canvas->restore();
}
sk_sp<SkImage> stampImage(int size) {
sk_sp<SkSurface> surface =
SkSurfaces::Raster(SkImageInfo::Make(size, size, colorType, kPremul_SkAlphaType));
drawStamp(surface->getCanvas(), size);
return surface->makeImageSnapshot();
}
void draw(SkCanvas* canvas) {
SkPaint paint;
paint.setColorFilter(SkColorFilters::Blend(0xFF7F00FF, SkBlendMode::kSrcIn));
paint.setAntiAlias(true);
SkSamplingOptions sampling(SkFilterMode::kLinear, SkMipmapMode::kLinear);
canvas->rotate(30);
canvas->translate(60, 0);
int stampSize = 200;
if (drawWithRasterImage) {
canvas->drawImage(stampImage(stampSize), 0, 0, sampling, &paint);
} else {
canvas->saveLayer(nullptr, &paint);
drawStamp(canvas, stampSize);
canvas->restore();
}
}