本文整理汇总了C++中SkPaint::setAlpha方法的典型用法代码示例。如果您正苦于以下问题:C++ SkPaint::setAlpha方法的具体用法?C++ SkPaint::setAlpha怎么用?C++ SkPaint::setAlpha使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkPaint
的用法示例。
在下文中一共展示了SkPaint::setAlpha方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paintSkBitmap
static void paintSkBitmap(PlatformContextSkia* platformContext, const NativeImageSkia& bitmap, const SkIRect& srcRect, const SkRect& destRect, const SkXfermode::Mode& compOp)
{
SkPaint paint;
paint.setXfermodeMode(compOp);
paint.setFilterBitmap(true);
int alpha = roundf(platformContext->getAlpha() * 256);
if (alpha > 255)
alpha = 255;
else if (alpha < 0)
alpha = 0;
paint.setAlpha(alpha);
skia::PlatformCanvas* canvas = platformContext->canvas();
ResamplingMode resampling = platformContext->isPrinting() ? RESAMPLE_NONE :
computeResamplingMode(bitmap, srcRect.width(), srcRect.height(),
SkScalarToFloat(destRect.width()),
SkScalarToFloat(destRect.height()));
if (resampling == RESAMPLE_AWESOME) {
drawResampledBitmap(*canvas, paint, bitmap, srcRect, destRect);
} else {
// No resampling necessary, we can just draw the bitmap. We want to
// filter it if we decided to do linear interpolation above, or if there
// is something interesting going on with the matrix (like a rotation).
// Note: for serialization, we will want to subset the bitmap first so
// we don't send extra pixels.
canvas->drawBitmapRect(bitmap, &srcRect, destRect, &paint);
}
}
示例2: applyOpacity
void SkSVGRenderContext::applyOpacity(SkScalar opacity, uint32_t flags) {
if (opacity >= 1) {
return;
}
const bool hasFill = SkToBool(this->fillPaint());
const bool hasStroke = SkToBool(this->strokePaint());
// We can apply the opacity as paint alpha iif it only affects one atomic draw.
// For now, this means a) the target node doesn't have any descendants, and
// b) it only has a stroke or a fill (but not both). Going forward, we may need
// to refine this heuristic (e.g. to accommodate markers).
if ((flags & kLeaf) && (hasFill ^ hasStroke)) {
auto* pctx = fPresentationContext.writable();
if (hasFill) {
pctx->fFillPaint.setAlpha(
SkScalarRoundToInt(opacity * pctx->fFillPaint.getAlpha()));
} else {
pctx->fStrokePaint.setAlpha(
SkScalarRoundToInt(opacity * pctx->fStrokePaint.getAlpha()));
}
} else {
// Expensive, layer-based fall back.
SkPaint opacityPaint;
opacityPaint.setAlpha(opacity_to_alpha(opacity));
// Balanced in the destructor, via restoreToCount().
fCanvas->saveLayer(nullptr, &opacityPaint);
}
}
示例3: paintSkBitmap
static void paintSkBitmap(PlatformContextSkia* platformContext, const NativeImageSkia& bitmap, const SkIRect& srcRect, const SkRect& destRect, const SkXfermode::Mode& compOp)
{
#if PLATFORM(CHROMIUM)
TRACE_EVENT("paintSkBitmap", platformContext, 0);
#endif
SkPaint paint;
paint.setXfermodeMode(compOp);
paint.setFilterBitmap(true);
paint.setAlpha(platformContext->getNormalizedAlpha());
paint.setLooper(platformContext->getDrawLooper());
// only antialias if we're rotated or skewed
paint.setAntiAlias(hasNon90rotation(platformContext));
SkCanvas* canvas = platformContext->canvas();
ResamplingMode resampling;
if (platformContext->isAccelerated())
resampling = RESAMPLE_LINEAR;
else
resampling = platformContext->printing() ? RESAMPLE_NONE :
computeResamplingMode(platformContext, bitmap, srcRect.width(), srcRect.height(), SkScalarToFloat(destRect.width()), SkScalarToFloat(destRect.height()));
if (resampling == RESAMPLE_AWESOME) {
drawResampledBitmap(*canvas, paint, bitmap, srcRect, destRect);
} else {
// No resampling necessary, we can just draw the bitmap. We want to
// filter it if we decided to do linear interpolation above, or if there
// is something interesting going on with the matrix (like a rotation).
// Note: for serialization, we will want to subset the bitmap first so
// we don't send extra pixels.
canvas->drawBitmapRect(bitmap.bitmap(), &srcRect, destRect, &paint);
}
platformContext->didDrawRect(destRect, paint, &bitmap.bitmap());
}
示例4: op
RENDERTHREAD_OPENGL_PIPELINE_TEST(BakedOpDispatcher, onLayerOp_bufferless) {
SkPaint layerPaint;
layerPaint.setAlpha(128);
OffscreenBuffer* buffer = nullptr; // no providing a buffer, should hit rect fallback case
LayerOp op(Rect(10, 10), Matrix4::identity(), nullptr, &layerPaint, &buffer);
testUnmergedGlopDispatch(renderThread, &op,
[](const Glop& glop) { ADD_FAILURE() << "Nothing should happen"; }, 0);
}
示例5: canvas
// Make sure our blits always map src==0 to a noop, and src==FF to full opaque
static void test_00_FF(skiatest::Reporter* reporter) {
static const int W = 256;
static const SkBitmap::Config gDstConfig[] = {
SkBitmap::kARGB_8888_Config,
SkBitmap::kRGB_565_Config,
// SkBitmap::kARGB_4444_Config,
// SkBitmap::kA8_Config,
};
static const struct {
SkColor fSrc;
SkColor fDst;
SkPMColor fResult32;
uint16_t fResult16;
uint8_t fResult8;
} gSrcRec[] = {
{ 0, 0, 0, 0, 0 },
{ 0, 0xFFFFFFFF, SkPackARGB32(0xFF, 0xFF, 0xFF, 0xFF), 0xFFFF, 0xFF },
{ 0xFFFFFFFF, 0, SkPackARGB32(0xFF, 0xFF, 0xFF, 0xFF), 0xFFFF, 0xFF },
{ 0xFFFFFFFF, 0xFFFFFFFF, SkPackARGB32(0xFF, 0xFF, 0xFF, 0xFF), 0xFFFF, 0xFF },
};
SkPaint paint;
SkBitmap srcBM;
srcBM.setConfig(SkBitmap::kARGB_8888_Config, W, 1);
srcBM.allocPixels();
for (size_t i = 0; i < SK_ARRAY_COUNT(gDstConfig); i++) {
SkBitmap dstBM;
dstBM.setConfig(gDstConfig[i], W, 1);
dstBM.allocPixels();
SkCanvas canvas(dstBM);
for (size_t j = 0; j < SK_ARRAY_COUNT(gSrcRec); j++) {
srcBM.eraseColor(gSrcRec[j].fSrc);
dstBM.eraseColor(gSrcRec[j].fDst);
for (int k = 0; k < 4; k++) {
bool dither = (k & 1) != 0;
bool blend = (k & 2) != 0;
if (gSrcRec[j].fSrc != 0 && blend) {
// can't make a numerical promise about blending anything
// but 0
// continue;
}
paint.setDither(dither);
paint.setAlpha(blend ? 0x80 : 0xFF);
canvas.drawBitmap(srcBM, 0, 0, &paint);
if (!check_color(dstBM, gSrcRec[j].fResult32, gSrcRec[j].fResult16,
gSrcRec[j].fResult8, reporter)) {
SkDebugf("--- src index %d dither %d blend %d\n", j, dither, blend);
}
}
}
}
}
示例6:
static void r1(SkLayerRasterizer* rast, SkPaint& p) {
rast->addLayer(p);
p.setAlpha(0x40);
p.setXfermodeMode(SkXfermode::kSrc_Mode);
p.setStyle(SkPaint::kStroke_Style);
p.setStrokeWidth(SK_Scalar1*2);
rast->addLayer(p);
}
示例7: drawInnerPath
static inline void drawInnerPath(PlatformContextSkia* context, const SkPath& path, SkPaint& paint, int width)
{
#if PLATFORM(CHROMIUM) && OS(DARWIN)
paint.setAlpha(128);
paint.setStrokeWidth(width * 0.5f);
context->canvas()->drawPath(path, paint);
context->didDrawPath(path, paint);
#endif
}
示例8: onDraw
virtual void onDraw(SkCanvas* canvas) {
SkShader* s =
SkShader::CreateBitmapShader(fBM, SkShader::kRepeat_TileMode,
SkShader::kMirror_TileMode);
SkPaint paint;
paint.setAlpha(0x80);
paint.setShader(s)->unref();
canvas->drawPaint(paint);
}
示例9: ShaderMaskBench
ShaderMaskBench(void* param, bool isOpaque, FontQuality fq) : INHERITED(param) {
fFQ = fq;
fText.set(STR);
fPaint.setAntiAlias(kBW != fq);
fPaint.setLCDRenderText(kLCD == fq);
fPaint.setAlpha(isOpaque ? 0xFF : 0x80);
fPaint.setShader(new SkColorShader)->unref();
}
示例10: draw_mode
void draw_mode(SkCanvas* canvas, SkXfermode* mode, int alpha,
SkScalar x, SkScalar y) {
SkPaint p;
canvas->drawBitmap(fSrcB, x, y, &p);
p.setAlpha(alpha);
p.setXfermode(mode);
canvas->drawBitmap(fDstB, x, y, &p);
}
示例11:
static void r3(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) {
p.setStyle(SkPaint::kStroke_Style);
p.setStrokeWidth(SK_Scalar1*3);
rastBuilder->addLayer(p);
p.setAlpha(0x20);
p.setStyle(SkPaint::kFill_Style);
p.setXfermodeMode(SkXfermode::kSrc_Mode);
rastBuilder->addLayer(p);
}
示例12: initPaint
static void initPaint(SkPaint& paint) {
// Make sure the paint is opaque, color, alpha, filter, etc.
// will be applied later when compositing the alpha8 texture
paint.setColor(SK_ColorBLACK);
paint.setAlpha(255);
paint.setColorFilter(NULL);
paint.setMaskFilter(NULL);
paint.setShader(NULL);
SkXfermode* mode = SkXfermode::Create(SkXfermode::kSrc_Mode);
SkSafeUnref(paint.setXfermode(mode));
}
示例13: drawHairlines
void drawHairlines(SkCanvas* canvas, const SkPath& path,
const SkPath& clipA, const SkPath& clipB) {
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
const SkAlpha fade = 0x33;
// draw path in hairline
paint.setColor(gPathColor);
paint.setAlpha(fade);
canvas->drawPath(path, paint);
// draw clips in hair line
paint.setColor(gClipAColor);
paint.setAlpha(fade);
canvas->drawPath(clipA, paint);
paint.setColor(gClipBColor);
paint.setAlpha(fade);
canvas->drawPath(clipB, paint);
}
示例14: InverseFillPE
static void r7(SkLayerRasterizer* rast, SkPaint& p, SkScalar interp) {
p.setPathEffect(makepe(interp, NULL))->unref();
rast->addLayer(p);
#if 0
p.setPathEffect(new InverseFillPE())->unref();
p.setXfermodeMode(SkXfermode::kSrcIn_Mode);
p.setXfermodeMode(SkXfermode::kClear_Mode);
p.setAlpha((1 - interp) * 255);
rast->addLayer(p);
#endif
}
示例15: drawBitmapRect
void PlatformGraphicsContextSkia::drawBitmapRect(const SkBitmap& bitmap,
const SkIRect* src, const SkRect& dst,
CompositeOperator op)
{
SkPaint paint;
setupPaintCommon(&paint);
paint.setAlpha(getNormalizedAlpha());
paint.setXfermodeMode(WebCoreCompositeToSkiaComposite(op));
fixPaintForBitmapsThatMaySeam(&paint);
mCanvas->drawBitmapRect(bitmap, src, dst, &paint);
}