本文整理汇总了C++中SkMatrix::setScale方法的典型用法代码示例。如果您正苦于以下问题:C++ SkMatrix::setScale方法的具体用法?C++ SkMatrix::setScale怎么用?C++ SkMatrix::setScale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkMatrix
的用法示例。
在下文中一共展示了SkMatrix::setScale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: makeMatrices
void makeMatrices() {
{
SkMatrix m;
m.setScale(SkIntToScalar(2), SkIntToScalar(3));
fMatrices.push_back(m);
}
{
SkMatrix m;
m.setScale(SkIntToScalar(2), SkIntToScalar(2));
fMatrices.push_back(m);
}
{
SkMatrix m;
m.setSkew(SkIntToScalar(2), SkIntToScalar(3));
fMatrices.push_back(m);
}
{
SkMatrix m;
m.setSkew(SkIntToScalar(2), SkIntToScalar(2));
fMatrices.push_back(m);
}
{
SkMatrix m;
m.setRotate(SkIntToScalar(30));
fMatrices.push_back(m);
}
}
示例2: test_treatAsSprite
static void test_treatAsSprite(skiatest::Reporter* reporter) {
const unsigned bilerBits = kSkSubPixelBitsForBilerp;
SkMatrix mat;
SkISize size;
SkRandom rand;
// assert: translate-only no-filter can always be treated as sprite
for (int i = 0; i < 1000; ++i) {
rand_matrix(&mat, rand, SkMatrix::kTranslate_Mask);
for (int j = 0; j < 1000; ++j) {
rand_size(&size, rand);
REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, 0));
}
}
// assert: rotate/perspect is never treated as sprite
for (int i = 0; i < 1000; ++i) {
rand_matrix(&mat, rand, SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask);
for (int j = 0; j < 1000; ++j) {
rand_size(&size, rand);
REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, 0));
REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits));
}
}
size.set(500, 600);
const SkScalar tooMuchSubpixel = 100.1f;
mat.setTranslate(tooMuchSubpixel, 0);
REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits));
mat.setTranslate(0, tooMuchSubpixel);
REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits));
const SkScalar tinySubPixel = 100.02f;
mat.setTranslate(tinySubPixel, 0);
REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, bilerBits));
mat.setTranslate(0, tinySubPixel);
REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, bilerBits));
const SkScalar twoThirds = SK_Scalar1 * 2 / 3;
const SkScalar bigScale = (size.width() + twoThirds) / size.width();
mat.setScale(bigScale, bigScale);
REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, false));
REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits));
const SkScalar oneThird = SK_Scalar1 / 3;
const SkScalar smallScale = (size.width() + oneThird) / size.width();
mat.setScale(smallScale, smallScale);
REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, false));
REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits));
const SkScalar oneFortyth = SK_Scalar1 / 40;
const SkScalar tinyScale = (size.width() + oneFortyth) / size.width();
mat.setScale(tinyScale, tinyScale);
REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, false));
REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, bilerBits));
}
示例3: textonpath_slide
static void textonpath_slide(SkCanvas* canvas) {
const char* text = "Displacement";
size_t len =strlen(text);
SkPath path;
path.moveTo(100, 300);
path.quadTo(300, 100, 500, 300);
path.offset(0, -100);
SkPaint paint;
paint.setAntiAlias(true);
paint.setTextSize(40);
paint.setStyle(SkPaint::kStroke_Style);
canvas->drawPath(path, paint);
paint.setStyle(SkPaint::kFill_Style);
SkScalar x = 50;
paint.setColor(0xFF008800);
canvas->drawTextOnPathHV(text, len, path,
x, paint.getTextSize()*2/3, paint);
paint.setColor(SK_ColorRED);
canvas->drawTextOnPathHV(text, len, path,
x + 60, 0, paint);
paint.setColor(SK_ColorBLUE);
canvas->drawTextOnPathHV(text, len, path,
x + 120, -paint.getTextSize()*2/3, paint);
path.offset(0, 200);
paint.setTextAlign(SkPaint::kRight_Align);
text = "Matrices";
len = strlen(text);
SkScalar pathLen = getpathlen(path);
SkMatrix matrix;
paint.setColor(SK_ColorBLACK);
paint.setStyle(SkPaint::kStroke_Style);
canvas->drawPath(path, paint);
paint.setStyle(SkPaint::kFill_Style);
paint.setTextSize(50);
canvas->drawTextOnPath(text, len, path, NULL, paint);
paint.setColor(SK_ColorRED);
matrix.setScale(-SK_Scalar1, SK_Scalar1);
matrix.postTranslate(pathLen, 0);
canvas->drawTextOnPath(text, len, path, &matrix, paint);
paint.setColor(SK_ColorBLUE);
matrix.setScale(SK_Scalar1, -SK_Scalar1);
canvas->drawTextOnPath(text, len, path, &matrix, paint);
paint.setColor(0xFF008800);
matrix.setScale(-SK_Scalar1, -SK_Scalar1);
matrix.postTranslate(pathLen, 0);
canvas->drawTextOnPath(text, len, path, &matrix, paint);
}
示例4: setWHZ
void setWHZ(int width, int height, int zoom) {
fZoom = zoom;
fBounds.set(0, 0, SkIntToScalar(width * zoom), SkIntToScalar(height * zoom));
fMatrix.setScale(SkIntToScalar(zoom), SkIntToScalar(zoom));
fInverse.setScale(SK_Scalar1 / zoom, SK_Scalar1 / zoom);
fShader.reset(sk_tool_utils::create_checkerboard_shader(
0xFFCCCCCC, 0xFFFFFFFF, zoom));
SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
fMinSurface.reset(SkSurface::NewRaster(info));
info = info.makeWH(width * zoom, height * zoom);
fMaxSurface.reset(SkSurface::NewRaster(info));
}
示例5: test_decompScale
static void test_decompScale(skiatest::Reporter* reporter) {
SkMatrix m;
m.reset();
REPORTER_ASSERT(reporter, check_decompScale(m));
m.setScale(2, 3);
REPORTER_ASSERT(reporter, check_decompScale(m));
m.setRotate(35, 0, 0);
REPORTER_ASSERT(reporter, check_decompScale(m));
m.setScale(1, 0);
REPORTER_ASSERT(reporter, !check_decompScale(m));
}
示例6: makeMatrices
void makeMatrices() {
{
SkMatrix m;
m.setIdentity();
fMatrices.push_back(m);
}
{
SkMatrix m;
m.setScale(SkIntToScalar(3), SkIntToScalar(2));
fMatrices.push_back(m);
}
{
SkMatrix m;
m.setScale(SkIntToScalar(2), SkIntToScalar(2));
fMatrices.push_back(m);
}
{
SkMatrix m;
m.setScale(SkIntToScalar(1), SkIntToScalar(2));
fMatrices.push_back(m);
}
{
SkMatrix m;
m.setScale(SkIntToScalar(4), SkIntToScalar(1));
fMatrices.push_back(m);
}
{
SkMatrix m;
m.setRotate(SkIntToScalar(90));
fMatrices.push_back(m);
}
{
SkMatrix m;
m.setSkew(SkIntToScalar(2), SkIntToScalar(3));
fMatrices.push_back(m);
}
{
SkMatrix m;
m.setRotate(SkIntToScalar(60));
fMatrices.push_back(m);
}
}
示例7: internalDrawBitmap
void SkPDFDevice::internalDrawBitmap(const SkMatrix& matrix,
const SkBitmap& bitmap,
const SkIRect* srcRect,
const SkPaint& paint) {
SkIRect subset = SkIRect::MakeWH(bitmap.width(), bitmap.height());
if (srcRect && !subset.intersect(*srcRect))
return;
SkPDFImage* image = SkPDFImage::CreateImage(bitmap, subset, paint);
if (!image)
return;
SkMatrix scaled;
// Adjust for origin flip.
scaled.setScale(1, -1);
scaled.postTranslate(0, 1);
// Scale the image up from 1x1 to WxH.
scaled.postScale(SkIntToScalar(subset.width()),
SkIntToScalar(subset.height()));
scaled.postConcat(matrix);
SkMatrix curTransform = setTransform(scaled);
updateGSFromPaint(paint, false);
fXObjectResources.push(image); // Transfer reference.
fContent.writeText("/X");
fContent.writeDecAsText(fXObjectResources.count() - 1);
fContent.writeText(" Do\n");
setTransform(curTransform);
}
示例8: scaleCanvas
DEF_TEST(RecordDraw_SetMatrixClobber, r) {
// Set up an SkRecord that just scales by 2x,3x.
SkRecord scaleRecord;
SkRecorder scaleCanvas(&scaleRecord, W, H);
SkMatrix scale;
scale.setScale(2, 3);
scaleCanvas.setMatrix(scale);
// Set up an SkRecord with an initial +20, +20 translate.
SkRecord translateRecord;
SkRecorder translateCanvas(&translateRecord, W, H);
SkMatrix translate;
translate.setTranslate(20, 20);
translateCanvas.setMatrix(translate);
SkRecordDraw(scaleRecord, &translateCanvas, nullptr, nullptr, 0, nullptr/*bbh*/, nullptr/*callback*/);
REPORTER_ASSERT(r, 4 == translateRecord.count());
assert_type<SkRecords::SetMatrix>(r, translateRecord, 0);
assert_type<SkRecords::Save> (r, translateRecord, 1);
assert_type<SkRecords::SetMatrix>(r, translateRecord, 2);
assert_type<SkRecords::Restore> (r, translateRecord, 3);
// When we look at translateRecord now, it should have its first +20,+20 translate,
// then a 2x,3x scale that's been concatted with that +20,+20 translate.
const SkRecords::SetMatrix* setMatrix;
setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 0);
REPORTER_ASSERT(r, setMatrix->matrix == translate);
setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 2);
SkMatrix expected = scale;
expected.postConcat(translate);
REPORTER_ASSERT(r, setMatrix->matrix == expected);
}
示例9: onDraw
virtual void onDraw(SkCanvas* canvas) {
this->drawBG(canvas);
SkMatrix matrix;
SkGroupShape* gs = new SkGroupShape;
SkAutoUnref aur(gs);
gs->appendShape(&fGroup);
matrix.setScale(-SK_Scalar1, SK_Scalar1);
matrix.postTranslate(SkIntToScalar(220), SkIntToScalar(240));
gs->appendShape(&fGroup, matrix);
matrix.setTranslate(SkIntToScalar(240), 0);
matrix.preScale(SK_Scalar1*2, SK_Scalar1*2);
gs->appendShape(&fGroup, matrix);
#if 1
SkPicture* pict = new SkPicture;
SkCanvas* cv = pict->beginRecording(1000, 1000);
cv->scale(SK_ScalarHalf, SK_ScalarHalf);
gs->draw(cv);
cv->translate(SkIntToScalar(680), SkIntToScalar(480));
cv->scale(-SK_Scalar1, SK_Scalar1);
gs->draw(cv);
pict->endRecording();
canvas->drawPicture(*pict);
pict->unref();
#endif
}
示例10:
static void r7(SkLayerRasterizer* rast, SkPaint& p) {
SkMatrix lattice;
lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0);
lattice.postSkew(SK_Scalar1/3, 0, 0, 0);
p.setPathEffect(new Dot2DPathEffect(SK_Scalar1*4, lattice))->unref();
rast->addLayer(p);
}
示例11: makepe
static SkPathEffect* makepe(float interp, SkTDArray<SkPoint>* pts) {
SkMatrix lattice;
SkScalar rad = 3 + SkIntToScalar(4) * (1 - interp);
lattice.setScale(rad*2, rad*2, 0, 0);
lattice.postSkew(SK_Scalar1/3, 0, 0, 0);
return new Dot2DPathEffect(rad, lattice, pts);
}
示例12: onDraw
virtual void onDraw(SkCanvas* canvas) {
this->drawBG(canvas);
SkMatrix saveM = *fMatrixRefs[3];
SkScalar c = SkIntToScalar(50);
fMatrixRefs[3]->preRotate(SkIntToScalar(30), c, c);
SkMatrix matrix;
SkGroupShape* gs = new SkGroupShape;
SkAutoUnref aur(gs);
gs->appendShape(&fGroup);
matrix.setScale(-SK_Scalar1, SK_Scalar1);
matrix.postTranslate(SkIntToScalar(220), SkIntToScalar(240));
gs->appendShape(&fGroup, matrix);
matrix.setTranslate(SkIntToScalar(240), 0);
matrix.preScale(SK_Scalar1*2, SK_Scalar1*2);
gs->appendShape(&fGroup, matrix);
#if 0
canvas->drawShape(gs);
#else
SkPicture pict;
SkCanvas* cv = pict.beginRecording(1000, 1000);
cv->scale(SK_ScalarHalf, SK_ScalarHalf);
cv->drawShape(gs);
cv->translate(SkIntToScalar(680), SkIntToScalar(480));
cv->scale(-SK_Scalar1, SK_Scalar1);
cv->drawShape(gs);
pict.endRecording();
canvas->drawPicture(pict);
#endif
*fMatrixRefs[3] = saveM;
}
示例13: make_strip
static void make_strip(Rec* rec, int texWidth, int texHeight) {
const SkScalar tx = SkIntToScalar(texWidth);
const SkScalar ty = SkIntToScalar(texHeight);
const int n = 24;
rec->fMode = SkCanvas::kTriangleStrip_VertexMode;
rec->fCount = 2 * (n + 1);
rec->fVerts = new SkPoint[rec->fCount];
rec->fTexs = new SkPoint[rec->fCount];
SkPoint* v = rec->fVerts;
SkPoint* t = rec->fTexs;
for (int i = 0; i < n; i++) {
SkScalar cos;
SkScalar sin = SkScalarSinCos(SK_ScalarPI * 2 * i / n, &cos);
v[i*2 + 0].set(cos/2, sin/2);
v[i*2 + 1].set(cos, sin);
t[i*2 + 0].set(tx * i / n, ty);
t[i*2 + 1].set(tx * i / n, 0);
}
v[2*n + 0] = v[0];
v[2*n + 1] = v[1];
t[2*n + 0].set(tx, ty);
t[2*n + 1].set(tx, 0);
SkMatrix m;
m.setScale(SkIntToScalar(100), SkIntToScalar(100));
m.postTranslate(SkIntToScalar(110), SkIntToScalar(110));
m.mapPoints(v, rec->fCount);
}
示例14: setBitmapDash
// Set a bitmap shader that mimics dashing by width-on, width-off.
// Returns false if it could not succeed (e.g. there was an existing shader)
static bool setBitmapDash(SkPaint* paint, int width) {
if (width <= 0 || paint->getShader())
return false;
SkColor c = paint->getColor();
SkBitmap bm;
bm.setConfig(SkBitmap::kARGB_8888_Config, 2, 1);
bm.allocPixels();
bm.lockPixels();
// set the ON pixel
*bm.getAddr32(0, 0) = SkPreMultiplyARGB(0xFF, SkColorGetR(c),
SkColorGetG(c), SkColorGetB(c));
// set the OFF pixel
*bm.getAddr32(1, 0) = 0;
bm.unlockPixels();
SkMatrix matrix;
matrix.setScale(SkIntToScalar(width), SK_Scalar1);
SkShader* s = SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode,
SkShader::kClamp_TileMode);
s->setLocalMatrix(matrix);
paint->setShader(s)->unref();
return true;
}
示例15: draw
void draw(SkCanvas* canvas,
const SkRect& rect,
const SkSize& deviceSize,
SkPaint::FilterLevel filterLevel,
SkImageFilter* input = NULL) {
SkRect dstRect;
canvas->getTotalMatrix().mapRect(&dstRect, rect);
canvas->save();
SkScalar deviceScaleX = SkScalarDiv(deviceSize.width(), dstRect.width());
SkScalar deviceScaleY = SkScalarDiv(deviceSize.height(), dstRect.height());
canvas->translate(rect.x(), rect.y());
canvas->scale(deviceScaleX, deviceScaleY);
canvas->translate(-rect.x(), -rect.y());
SkMatrix matrix;
matrix.setScale(SkScalarInvert(deviceScaleX),
SkScalarInvert(deviceScaleY));
SkAutoTUnref<SkImageFilter> imageFilter(
SkMatrixImageFilter::Create(matrix, filterLevel, input));
SkPaint filteredPaint;
filteredPaint.setImageFilter(imageFilter.get());
canvas->saveLayer(&rect, &filteredPaint);
SkPaint paint;
paint.setColor(0xFF00FF00);
SkRect ovalRect = rect;
ovalRect.inset(SkIntToScalar(4), SkIntToScalar(4));
canvas->drawOval(ovalRect, paint);
canvas->restore(); // for saveLayer
canvas->restore();
}