本文整理汇总了C++中SkPaint::setARGB方法的典型用法代码示例。如果您正苦于以下问题:C++ SkPaint::setARGB方法的具体用法?C++ SkPaint::setARGB怎么用?C++ SkPaint::setARGB使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkPaint
的用法示例。
在下文中一共展示了SkPaint::setARGB方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setupShapePaint
void setupShapePaint(SkCanvas* canvas, GrColor color, SkXfermode::Mode mode, SkPaint* paint) {
paint->setColor(color);
if (mode == SkXfermode::kPlus_Mode) {
// Check for overflow, otherwise we might get confusing AA artifacts.
int maxSum = SkTMax(SkTMax(SkColorGetA(kBGColor) + SkColorGetA(color),
SkColorGetR(kBGColor) + SkColorGetR(color)),
SkTMax(SkColorGetG(kBGColor) + SkColorGetG(color),
SkColorGetB(kBGColor) + SkColorGetB(color)));
if (maxSum > 255) {
SkPaint dimPaint;
dimPaint.setAntiAlias(false);
dimPaint.setXfermode(SkXfermode::Create(SkXfermode::kDstIn_Mode));
if (255 != paint->getAlpha()) {
// Dim the src and dst colors.
dimPaint.setARGB(255 * 255 / maxSum, 0, 0, 0);
paint->setAlpha(255 * paint->getAlpha() / maxSum);
} else {
// Just clear the dst, we need to preserve the paint's opacity.
dimPaint.setARGB(0, 0, 0, 0);
}
canvas->drawRectCoords(-kShapeSpacing/2, -kShapeSpacing/2,
kShapeSpacing/2 + 3 * kShapeTypeSpacing,
kShapeSpacing/2, dimPaint);
}
}
}
示例2: paintButtonLike
static void paintButtonLike(RenderTheme* theme, RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect)
{
SkCanvas* const canvas = i.context->platformContext()->canvas();
SkPaint paint;
SkRect skrect;
const int right = rect.x() + rect.width();
const int bottom = rect.y() + rect.height();
SkColor baseColor = SkColorSetARGB(0xff, 0xdd, 0xdd, 0xdd);
if (o->style()->hasBackground())
baseColor = o->style()->backgroundColor().rgb();
double h, s, l;
Color(baseColor).getHSL(h, s, l);
// Our standard gradient is from 0xdd to 0xf8. This is the amount of
// increased luminance between those values.
SkColor lightColor(brightenColor(h, s, l, 0.105));
// If the button is too small, fallback to drawing a single, solid color
if (rect.width() < 5 || rect.height() < 5) {
paint.setColor(baseColor);
skrect.set(rect.x(), rect.y(), right, bottom);
canvas->drawRect(skrect, paint);
return;
}
const int borderAlpha = theme->isHovered(o) ? 0x80 : 0x55;
paint.setARGB(borderAlpha, 0, 0, 0);
canvas->drawLine(rect.x() + 1, rect.y(), right - 1, rect.y(), paint);
canvas->drawLine(right - 1, rect.y() + 1, right - 1, bottom - 1, paint);
canvas->drawLine(rect.x() + 1, bottom - 1, right - 1, bottom - 1, paint);
canvas->drawLine(rect.x(), rect.y() + 1, rect.x(), bottom - 1, paint);
paint.setARGB(0xff, 0, 0, 0);
SkPoint p[2];
const int lightEnd = theme->isPressed(o) ? 1 : 0;
const int darkEnd = !lightEnd;
p[lightEnd].set(SkIntToScalar(rect.x()), SkIntToScalar(rect.y()));
p[darkEnd].set(SkIntToScalar(rect.x()), SkIntToScalar(bottom - 1));
SkColor colors[2];
colors[0] = lightColor;
colors[1] = baseColor;
SkShader* shader = SkGradientShader::CreateLinear(
p, colors, NULL, 2, SkShader::kClamp_TileMode, NULL);
paint.setStyle(SkPaint::kFill_Style);
paint.setShader(shader);
shader->unref();
skrect.set(rect.x() + 1, rect.y() + 1, right - 1, bottom - 1);
canvas->drawRect(skrect, paint);
paint.setShader(NULL);
paint.setColor(brightenColor(h, s, l, -0.0588));
canvas->drawPoint(rect.x() + 1, rect.y() + 1, paint);
canvas->drawPoint(right - 2, rect.y() + 1, paint);
canvas->drawPoint(rect.x() + 1, bottom - 2, paint);
canvas->drawPoint(right - 2, bottom - 2, paint);
}
示例3: writeFrames
static void writeFrames() {
const int scale = 5;
for (int index = 0; index < (int) SK_ARRAY_COUNT(frameSizes); ++index) {
SkDRect bounds;
bool boundsSet = false;
int frameSize = frameSizes[index];
for (int fIndex = 0; fIndex < frameSize; ++fIndex) {
const SkDConic& dC = frames[index][fIndex];
SkDConic dConic = {{{ {dC.fPts[0].fX * scale, dC.fPts[0].fY * scale },
{dC.fPts[1].fX * scale, dC.fPts[1].fY * scale },
{dC.fPts[2].fX * scale, dC.fPts[2].fY * scale }}}, dC.fWeight };
SkDRect dBounds;
dBounds.setBounds(dConic);
if (!boundsSet) {
bounds = dBounds;
boundsSet = true;
} else {
bounds.add((SkDPoint&) dBounds.fLeft);
bounds.add((SkDPoint&) dBounds.fRight);
}
}
bounds.fLeft -= 10;
bounds.fTop -= 10;
bounds.fRight += 10;
bounds.fBottom += 10;
SkBitmap bitmap;
bitmap.tryAllocPixels(SkImageInfo::MakeN32Premul(
SkScalarRoundToInt(SkDoubleToScalar(bounds.width())),
SkScalarRoundToInt(SkDoubleToScalar(bounds.height()))));
SkCanvas canvas(bitmap);
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
canvas.translate(SkDoubleToScalar(-bounds.fLeft), SkDoubleToScalar(-bounds.fTop));
canvas.drawColor(SK_ColorWHITE);
for (int fIndex = 0; fIndex < frameSize; ++fIndex) {
const SkDConic& dC = frames[index][fIndex];
SkDConic dConic = {{{ {dC.fPts[0].fX * scale, dC.fPts[0].fY * scale },
{dC.fPts[1].fX * scale, dC.fPts[1].fY * scale },
{dC.fPts[2].fX * scale, dC.fPts[2].fY * scale }}}, dC.fWeight };
SkPath path;
path.moveTo(dConic.fPts[0].asSkPoint());
path.conicTo(dConic.fPts[1].asSkPoint(), dConic.fPts[2].asSkPoint(), dConic.fWeight);
if (fIndex < 2) {
paint.setARGB(0x80, 0xFF, 0, 0);
} else {
paint.setARGB(0x80, 0, 0, 0xFF);
}
canvas.drawPath(path, paint);
}
SkString filename("c:\\Users\\caryclark\\Documents\\");
filename.appendf("f%d.png", index);
SkImageEncoder::EncodeFile(filename.c_str(), bitmap, SkImageEncoder::kPNG_Type, 100);
}
}
示例4: onDraw
void onDraw(SkCanvas* canvas) override {
const SkAlpha kAlphaValue[] = { 0xFF, 0x40 };
const SkScalar margin = 15;
canvas->translate(margin, margin);
SkPaint paint;
for (int p = 0; p < fPaths.count(); ++p) {
canvas->save();
for (size_t a = 0; a < SK_ARRAY_COUNT(kAlphaValue); ++a) {
paint.setARGB(kAlphaValue[a], 0, 0, 0);
for (int aa = 0; aa < 2; ++aa) {
paint.setAntiAlias(SkToBool(aa));
for (int fh = 0; fh < 2; ++fh) {
paint.setStyle(fh ? SkPaint::kStroke_Style : SkPaint::kFill_Style);
const SkRect& bounds = fPaths[p].getBounds();
canvas->save();
canvas->translate(-bounds.fLeft, -bounds.fTop);
canvas->drawPath(fPaths[p], paint);
canvas->restore();
canvas->translate(110, 0);
}
}
}
canvas->restore();
canvas->translate(0, 110);
}
canvas->restore();
this->drawGiantCircle(canvas);
}
示例5: device
SkBitmap
skiaCreateSampleImage(caskbench_context_t *ctx)
{
int i, x, y;
SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config, 160, 40);
SkImageInfo info = SkImageInfo::Make(160, 40,
kBGRA_8888_SkColorType,
kPremul_SkAlphaType);
bitmap.allocPixels(info);
SkBitmapDevice device(bitmap);
SkCanvas canvas(&device);
SkPaint paint;
SkRect r;
canvas.clear(0);
x = 5;
for (i=0; i<16; i++) {
paint.setARGB(255, 255/(i+1), 255, 16*i);
x += 10;
y = (i%2)*10;
r.set(x, y, x+10, y+10);
canvas.drawRect(r, paint);
}
canvas.flush();
return bitmap;
}
示例6: render
void render() {
#if USE_SKIA_OPENGL
bbutil_clear();
#endif
/************************** BEGIN USER RENDER CODE ***************************/
// Clear the entire canvas to a solid colour
SkPaint clearColor;
clearColor.setARGB(255,0xdd,0xdd,0xdd);
SkRect fullScreen;
fullScreen.set(0,0,width,height);
canvas->drawRect(fullScreen, clearColor);
// Draw the current demo
if (demos[currentIndex])
demos[currentIndex]->onDraw();
/**************************** END USER RENDER CODE ***************************/
// Draw the contents of the canvas to the screen
#if USE_SKIA_OPENGL
device->flush();
bbutil_swap(0);
#else
bbutil_swap(currentSurface);
currentSurface = 1 - currentSurface;
canvas->setBitmapDevice(drawingSurface[currentSurface]);
#endif
}
示例7: onDrawContent
virtual void onDrawContent(SkCanvas* canvas) {
const char* str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
SkPaint paint;
SkScalar x = SkIntToScalar(10);
SkScalar y = SkIntToScalar(20);
paint.setFlags(0x105);
paint.setARGB(fByte, 0xFF, 0xFF, 0xFF);
paint.setMaskFilter(SkBlurMaskFilter::Create(SkIntToScalar(3),
SkBlurMaskFilter::kNormal_BlurStyle));
paint.getMaskFilter()->unref();
SkRandom rand;
for (int ps = 6; ps <= 35; ps++) {
paint.setColor(rand.nextU() | (0xFF << 24));
paint.setTextSize(SkIntToScalar(ps));
paint.setTextSize(SkIntToScalar(24));
canvas->drawText(str, strlen(str), x, y, paint);
y += paint.getFontMetrics(NULL);
}
if (false) { // avoid bit rot, suppress warning
check_for_nonwhite(canvas->getDevice()->accessBitmap(false), fByte);
SkDebugf("------ byte %x\n", fByte);
}
if (false) {
fByte += 1;
fByte &= 0xFF;
this->inval(NULL);
}
}
示例8: onDraw
void LayerAndroid::onDraw(SkCanvas* canvas, SkScalar opacity) {
if (m_haveClip) {
SkRect r;
r.set(0, 0, getSize().width(), getSize().height());
canvas->clipRect(r);
}
if (!prepareContext())
return;
// we just have this save/restore for opacity...
SkAutoCanvasRestore restore(canvas, true);
int canvasOpacity = SkScalarRound(opacity * 255);
if (canvasOpacity < 255)
canvas->setDrawFilter(new OpacityDrawFilter(canvasOpacity));
canvas->drawPicture(*m_recordingPicture);
#if ENABLE(WEBGL)
if (m_context.get()) {
m_context->paint(canvas);
}
#endif
if (m_extra)
m_extra->draw(canvas, this);
#ifdef LAYER_DEBUG
float w = getSize().width();
float h = getSize().height();
SkPaint paint;
paint.setARGB(128, 255, 0, 0);
canvas->drawLine(0, 0, w, h, paint);
canvas->drawLine(0, h, w, 0, paint);
paint.setARGB(128, 0, 255, 0);
canvas->drawLine(0, 0, 0, h, paint);
canvas->drawLine(0, h, w, h, paint);
canvas->drawLine(w, h, w, 0, paint);
canvas->drawLine(w, 0, 0, 0, paint);
if (m_isFixed) {
SkRect layerRect = computeLayerRect(this);
SkPaint paint;
paint.setARGB(128, 0, 0, 255);
canvas->drawRect(layerRect, paint);
}
#endif
}
示例9: contentDraw
void FixedPositioning::contentDraw(SkCanvas* canvas, Layer::PaintStyle style)
{
if (TilesManager::instance()->getShowVisualIndicator()) {
SkPaint paint;
paint.setARGB(80, 255, 0, 0);
canvas->drawRect(m_fixedRect, paint);
}
}
示例10: draw_scene
static void draw_scene(SkCanvas* canvas, const SkHighContrastConfig& config) {
SkRect bounds = SkRect::MakeLTRB(0.0f, 0.0f, 1.0f, 1.0f);
SkPaint xferPaint;
xferPaint.setColorFilter(SkHighContrastFilter::Make(config));
canvas->saveLayer(&bounds, &xferPaint);
SkPaint paint;
bounds = SkRect::MakeLTRB(0.1f, 0.2f, 0.9f, 0.4f);
paint.setARGB(0xff, 0x66, 0x11, 0x11);
canvas->drawRect(bounds, paint);
SkFont font;
font.setSize(0.15f);
font.setEdging(SkFont::Edging::kAlias);
paint.setARGB(0xff, 0xbb, 0x77, 0x77);
canvas->drawString("A", 0.15f, 0.35f, font, paint);
bounds = SkRect::MakeLTRB(0.1f, 0.8f, 0.9f, 1.0f);
paint.setARGB(0xff, 0xcc, 0xcc, 0xff);
canvas->drawRect(bounds, paint);
paint.setARGB(0xff, 0x88, 0x88, 0xbb);
canvas->drawString("Z", 0.75f, 0.95f, font, paint);
bounds = SkRect::MakeLTRB(0.1f, 0.4f, 0.9f, 0.6f);
SkPoint pts[] = { { 0, 0 }, { 1, 0 } };
SkColor colors[] = { SK_ColorWHITE, SK_ColorBLACK };
SkScalar pos[] = { 0.2f, 0.8f };
paint.setShader(SkGradientShader::MakeLinear(
pts, colors, pos,
SK_ARRAY_COUNT(colors), SkTileMode::kClamp));
canvas->drawRect(bounds, paint);
bounds = SkRect::MakeLTRB(0.1f, 0.6f, 0.9f, 0.8f);
SkColor colors2[] = { SK_ColorGREEN, SK_ColorWHITE };
paint.setShader(SkGradientShader::MakeLinear(
pts, colors2, pos,
SK_ARRAY_COUNT(colors2), SkTileMode::kClamp));
canvas->drawRect(bounds, paint);
canvas->restore();
}
示例11: writePng
static void writePng(const SkConic& c, const SkConic ch[2], const char* name) {
const int scale = 10;
SkConic conic, chopped[2];
for (int index = 0; index < 3; ++index) {
conic.fPts[index].fX = c.fPts[index].fX * scale;
conic.fPts[index].fY = c.fPts[index].fY * scale;
for (int chIndex = 0; chIndex < 2; ++chIndex) {
chopped[chIndex].fPts[index].fX = ch[chIndex].fPts[index].fX * scale;
chopped[chIndex].fPts[index].fY = ch[chIndex].fPts[index].fY * scale;
}
}
conic.fW = c.fW;
chopped[0].fW = ch[0].fW;
chopped[1].fW = ch[1].fW;
SkBitmap bitmap;
SkRect bounds;
conic.computeTightBounds(&bounds);
bounds.outset(10, 10);
bitmap.tryAllocPixels(SkImageInfo::MakeN32Premul(
SkScalarRoundToInt(bounds.width()), SkScalarRoundToInt(bounds.height())));
SkCanvas canvas(bitmap);
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
canvas.translate(-bounds.fLeft, -bounds.fTop);
canvas.drawColor(SK_ColorWHITE);
SkPath path;
path.moveTo(conic.fPts[0]);
path.conicTo(conic.fPts[1], conic.fPts[2], conic.fW);
paint.setARGB(0x80, 0xFF, 0, 0);
canvas.drawPath(path, paint);
path.reset();
path.moveTo(chopped[0].fPts[0]);
path.conicTo(chopped[0].fPts[1], chopped[0].fPts[2], chopped[0].fW);
path.moveTo(chopped[1].fPts[0]);
path.conicTo(chopped[1].fPts[1], chopped[1].fPts[2], chopped[1].fW);
paint.setARGB(0x80, 0, 0, 0xFF);
canvas.drawPath(path, paint);
SkString filename("c:\\Users\\caryclark\\Documents\\");
filename.appendf("%s.png", name);
SkImageEncoder::EncodeFile(filename.c_str(), bitmap,
SkImageEncoder::kPNG_Type, 100);
}
示例12: writeDPng
static void writeDPng(const SkDConic& dC, const char* name) {
const int scale = 5;
SkDConic dConic = {{{ {dC.fPts[0].fX * scale, dC.fPts[0].fY * scale },
{dC.fPts[1].fX * scale, dC.fPts[1].fY * scale },
{dC.fPts[2].fX * scale, dC.fPts[2].fY * scale }}}, dC.fWeight };
SkBitmap bitmap;
SkDRect bounds;
bounds.setBounds(dConic);
bounds.fLeft -= 10;
bounds.fTop -= 10;
bounds.fRight += 10;
bounds.fBottom += 10;
bitmap.tryAllocPixels(SkImageInfo::MakeN32Premul(
SkScalarRoundToInt(SkDoubleToScalar(bounds.width())),
SkScalarRoundToInt(SkDoubleToScalar(bounds.height()))));
SkCanvas canvas(bitmap);
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
canvas.translate(SkDoubleToScalar(-bounds.fLeft), SkDoubleToScalar(-bounds.fTop));
canvas.drawColor(SK_ColorWHITE);
SkPath path;
path.moveTo(dConic.fPts[0].asSkPoint());
path.conicTo(dConic.fPts[1].asSkPoint(), dConic.fPts[2].asSkPoint(), dConic.fWeight);
paint.setARGB(0x80, 0xFF, 0, 0);
canvas.drawPath(path, paint);
path.reset();
const int chops = 2;
for (int tIndex = 0; tIndex < chops; ++tIndex) {
SkDConic chopped = dConic.subDivide(tIndex / (double) chops,
(tIndex + 1) / (double) chops);
path.moveTo(chopped.fPts[0].asSkPoint());
path.conicTo(chopped.fPts[1].asSkPoint(), chopped.fPts[2].asSkPoint(), chopped.fWeight);
}
paint.setARGB(0x80, 0, 0, 0xFF);
canvas.drawPath(path, paint);
SkString filename("c:\\Users\\caryclark\\Documents\\");
filename.appendf("%s.png", name);
SkImageEncoder::EncodeFile(filename.c_str(), bitmap,
SkImageEncoder::kPNG_Type, 100);
}
示例13: onDraw
void onDraw(SkCanvas* canvas) override {
canvas->save();
canvas->scale(1, -1);
canvas->translate(0, -kHeight);
for (int p = 0; p < fPaths.count(); ++p) {
SkPaint paint;
paint.setARGB(0xff, 0, 0, 0);
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(0);
canvas->drawPath(fPaths[p], paint);
}
canvas->restore();
}
示例14: onDraw
void onDraw(SkCanvas* canvas) override {
static const SkAlpha kAlphaValue[] = { 0xFF, 0x40 };
static const SkScalar kWidths[] = { 0, 0.5f, 1.5f };
enum {
kMargin = 5,
};
int wrapX = canvas->getDeviceSize().fWidth - kMargin;
SkScalar maxH = 0;
canvas->translate(SkIntToScalar(kMargin), SkIntToScalar(kMargin));
canvas->save();
SkScalar x = SkIntToScalar(kMargin);
for (int p = 0; p < fPaths.count(); ++p) {
for (size_t a = 0; a < SK_ARRAY_COUNT(kAlphaValue); ++a) {
for (int aa = 0; aa < 2; ++aa) {
for (size_t w = 0; w < SK_ARRAY_COUNT(kWidths); w++) {
const SkRect& bounds = fPaths[p].getBounds();
if (x + bounds.width() > wrapX) {
canvas->restore();
canvas->translate(0, maxH + SkIntToScalar(kMargin));
canvas->save();
maxH = 0;
x = SkIntToScalar(kMargin);
}
SkPaint paint;
paint.setARGB(kAlphaValue[a], 0, 0, 0);
paint.setAntiAlias(SkToBool(aa));
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(kWidths[w]);
canvas->save();
canvas->translate(-bounds.fLeft, -bounds.fTop);
canvas->drawPath(fPaths[p], paint);
canvas->restore();
maxH = SkMaxScalar(maxH, bounds.height());
SkScalar dx = bounds.width() + SkIntToScalar(kMargin);
x += dx;
canvas->translate(dx, 0);
}
}
}
}
canvas->restore();
}
示例15: onDrawContent
void onDrawContent(SkCanvas* canvas) override {
SkPaint paint;
canvas->translate(0, 50);
paint.setColor(SK_ColorBLUE);
paint.setPathEffect(make_pe(2, fPhase));
canvas->drawPath(fPath, paint);
canvas->translate(0, 50);
paint.setARGB(0xFF, 0, 0xBB, 0);
paint.setPathEffect(make_pe(3, fPhase));
canvas->drawPath(fPath, paint);
canvas->translate(0, 50);
paint.setARGB(0xFF, 0, 0, 0);
paint.setPathEffect(make_warp_pe(fPhase));
TestRastBuilder testRastBuilder;
paint.setRasterizer(testRastBuilder.detach());
canvas->drawPath(fPath, paint);
}