当前位置: 首页>>代码示例>>Java>>正文


Java Canvas.save方法代码示例

本文整理汇总了Java中android.graphics.Canvas.save方法的典型用法代码示例。如果您正苦于以下问题:Java Canvas.save方法的具体用法?Java Canvas.save怎么用?Java Canvas.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.graphics.Canvas的用法示例。


在下文中一共展示了Canvas.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: draw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void draw(@NonNull Canvas canvas, CharSequence text,
                 int start, int end, float x,
                 int top, int y, int bottom, @NonNull Paint paint) {
    Drawable d = getCachedDrawable();
    Rect rect = d.getBounds();
    canvas.save();
    final float fontHeight = paint.getFontMetrics().descent - paint.getFontMetrics().ascent;
    int transY = bottom - rect.bottom;
    if (rect.height() < fontHeight) { // this is the fucking code which I waste 3 days
        if (mVerticalAlignment == ALIGN_BASELINE) {
            transY -= paint.getFontMetricsInt().descent;
        } else if (mVerticalAlignment == ALIGN_CENTER) {
            transY -= (fontHeight - rect.height()) / 2;
        } else if (mVerticalAlignment == ALIGN_TOP) {
            transY -= fontHeight - rect.height();
        }
    } else {
        if (mVerticalAlignment == ALIGN_BASELINE) {
            transY -= paint.getFontMetricsInt().descent;
        }
    }
    canvas.translate(x, transY);
    d.draw(canvas);
    canvas.restore();
}
 
开发者ID:hoangkien0705,项目名称:Android-UtilCode,代码行数:27,代码来源:SpannableStringUtils.java

示例2: drawTopLeftTip

import android.graphics.Canvas; //导入方法依赖的package包/类
/**
 * 左上角画梯形
 * @param canvas
 * @param realWaist 腰长
 */
private void drawTopLeftTip(Canvas canvas, float realWaist) {
    path.moveTo(this.realStartDisH, 0);
    path.lineTo(this.realStartDisH + realWaist, 0);
    path.lineTo(0, this.realStartDisH + realWaist);
    path.lineTo(0, this.realStartDisH);
    path.close();
    canvas.drawPath(path, backPaint);
    canvas.save();

    Paint.FontMetricsInt fontMetrics = textPaint.getFontMetricsInt();
    float dis = (waistDis /2  + this.startDisH) /2;
    float disY = dis - (fontMetrics.bottom + fontMetrics.top) / 2f;
    canvas.rotate(-45, dis, dis);
    canvas.drawText(tipContent, dis, disY, textPaint);
    canvas.rotate(45, dis, dis);
    canvas.restore();
}
 
开发者ID:zhqchen,项目名称:CornerTipView,代码行数:23,代码来源:CornerTipView.java

示例3: addLogoToQRCode

import android.graphics.Canvas; //导入方法依赖的package包/类
/**
 * 添加logo到二维码图片上
 *
 * @param src
 * @param logo
 * @return
 */
private static Bitmap addLogoToQRCode(Bitmap src, Bitmap logo) {
    if (src == null || logo == null) {
        return src;
    }

    int srcWidth = src.getWidth();
    int srcHeight = src.getHeight();
    int logoWidth = logo.getWidth();
    int logoHeight = logo.getHeight();

    float scaleFactor = srcWidth * 1.0f / 5 / logoWidth;
    Bitmap bitmap = Bitmap.createBitmap(srcWidth, srcHeight, Bitmap.Config.ARGB_8888);
    try {
        Canvas canvas = new Canvas(bitmap);
        canvas.drawBitmap(src, 0, 0, null);
        canvas.scale(scaleFactor, scaleFactor, srcWidth / 2, srcHeight / 2);
        canvas.drawBitmap(logo, (srcWidth - logoWidth) / 2, (srcHeight - logoHeight) / 2, null);
        canvas.save(Canvas.ALL_SAVE_FLAG);
        canvas.restore();
    } catch (Exception e) {
        bitmap = null;
    }
    return bitmap;
}
 
开发者ID:devzwy,项目名称:NeiHanDuanZiTV,代码行数:32,代码来源:QRCodeEncoder.java

示例4: draw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void draw(Canvas canvas) {
    int saveCount = canvas.save();

    mTempBounds.set(mBounds);
    mTempBounds.inset(mStrokeInset, mStrokeInset);
    mTempBounds.inset(mTempBounds.width() * (1.0f - mScale) / 2.0f, mTempBounds.width() * (1.0f - mScale) / 2.0f);

    canvas.rotate(mGroupRotation, mTempBounds.centerX(), mTempBounds.centerY());

    mPaint.setColor(mColor);
    mPaint.setAlpha((int) (MAX_ALPHA * mScale));
    mPaint.setStrokeWidth(mStrokeWidth * mScale);

    if (mSwipeDegrees != 0) {
        for (int i = 0; i < mGearCount; i++) {
            canvas.drawArc(mTempBounds, mStartDegrees + DEGREE_360 / mGearCount * i, mSwipeDegrees, false, mPaint);
        }
    }

    canvas.restoreToCount(saveCount);
}
 
开发者ID:ZhuoKeTeam,项目名称:JueDiQiuSheng,代码行数:23,代码来源:GearLoadingRenderer.java

示例5: draw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void draw(Canvas canvas, Position position) {
    canvas.drawPath(mPath, (flags & SELECTED) != 0
            ? mSelectedPaint : mBackgroundPaint);
    canvas.drawPath(mPath, (flags & SELECTED) != 0
            ? mSelectedPaint : mOutlinePaint);

    if (mView != null) {
        int state = canvas.save();
        canvas.translate(mView.getLeft(), mView.getTop());
        // keep icons "upright" if we get displayed on TOP position
        if (position != Position.TOP) {
            canvas.rotate(mStart + mSweep / 2 - 270);
        } else {
            canvas.rotate(mStart + mSweep / 2 - 90);
        }
        canvas.translate(-mView.getWidth() / 2, -mView.getHeight() / 2);

        mView.draw(canvas);
        canvas.restoreToCount(state);
    }
}
 
开发者ID:WrBug,项目名称:GravityBox,代码行数:23,代码来源:PieItem.java

示例6: draw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void draw(Canvas canvas, Paint paint) {
    float rWidth=getWidth()/5;
    float rHeight=getHeight()/5;
    for (int i = 0; i < 2; i++) {
        canvas.save();
        canvas.translate(translateX[i], translateY[i]);
        canvas.rotate(degrees);
        canvas.scale(scaleFloat,scaleFloat);
        RectF rectF=new RectF(-rWidth/2,-rHeight/2,rWidth/2,rHeight/2);
        canvas.drawRect(rectF,paint);
        canvas.restore();
    }
}
 
开发者ID:monkeywiiu,项目名称:Discover,代码行数:15,代码来源:CubeTransitionIndicator.java

示例7: draw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void draw(Canvas canvas, Paint paint) {
    float circleSpacing=4;
    float radius=(Math.min(getWidth(),getHeight())-circleSpacing*2)/6;
    float x = getWidth()/ 2-(radius*2+circleSpacing);
    float y=getHeight() / 2;
    for (int i = 0; i < 3; i++) {
        canvas.save();
        float translateX=x+(radius*2)*i+circleSpacing*i;
        canvas.translate(translateX, y);
        canvas.scale(scaleFloats[i], scaleFloats[i]);
        canvas.drawCircle(0, 0, radius, paint);
        canvas.restore();
    }
}
 
开发者ID:monkeywiiu,项目名称:Discover,代码行数:16,代码来源:BallPulseIndicator.java

示例8: onDrawMainUpView

import android.graphics.Canvas; //导入方法依赖的package包/类
/**
 * 重寫了繪製的函數.
 */
@Override
public boolean onDrawMainUpView(Canvas canvas)
{
    canvas.save();
    if (!isDrawUpRect)
    {
        // 绘制阴影.
        onDrawShadow(canvas);
        // 绘制最上层的边框.
        onDrawUpRect(canvas);
    }
    // 绘制焦点子控件.
    if (mFocusView != null && (!isDrawUpRect && isInDraw))
    {
        onDrawFocusView(canvas);
    }
    //
    if (isDrawUpRect)
    {
        // 绘制阴影.
        onDrawShadow(canvas);
        // 绘制最上层的边框.
        onDrawUpRect(canvas);
    }
    canvas.restore();
    return true;
}
 
开发者ID:Dreamxiaoxuan,项目名称:AndroidTvDemo,代码行数:31,代码来源:OpenEffectBridge.java

示例9: draw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void draw(Canvas canvas) {
    if(!mClipOutlines){
        super.draw(canvas);
        return;
    }
    final int state = canvas.save();
    mRevealPath.reset();
    mRevealPath.addCircle(mCenterX, mCenterY, mRadius, Path.Direction.CW);
    canvas.clipPath(mRevealPath);
    super.draw(canvas);
    canvas.restoreToCount(state);
}
 
开发者ID:woxingxiao,项目名称:GracefulMovies,代码行数:14,代码来源:ClipRevealFrame.java

示例10: draw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override public void draw(@NonNull Canvas canvas) {
  super.draw(canvas);

  int width = getWidth();
  int height = getHeight();
  if (insets != null && insetForeground != null) {
    int sc = canvas.save();
    canvas.translate(getScrollX(), getScrollY());

    // Top
    tempRect.set(0, 0, width, insets.top);
    insetForeground.setBounds(tempRect);
    insetForeground.draw(canvas);

    // Bottom
    tempRect.set(0, height - insets.bottom, width, height);
    insetForeground.setBounds(tempRect);
    insetForeground.draw(canvas);

    // Left
    tempRect.set(0, insets.top, insets.left, height - insets.bottom);
    insetForeground.setBounds(tempRect);
    insetForeground.draw(canvas);

    // Right
    tempRect.set(width - insets.right, insets.top, width, height - insets.bottom);
    insetForeground.setBounds(tempRect);
    insetForeground.draw(canvas);

    canvas.restoreToCount(sc);
  }
}
 
开发者ID:rogues-dev,项目名称:superglue,代码行数:33,代码来源:NonConsumingScrimInsetsFrameLayout.java

示例11: draw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void draw(Canvas canvas, CharSequence text, int start, int end,
                 float x, int top, int y, int bottom, Paint paint) {
    Drawable drawable = getDrawable();
    canvas.save();
    int transY = 0;
    transY = ((bottom - top) - drawable.getBounds().bottom) / 2 + top;
    canvas.translate(x, transY);
    drawable.draw(canvas);
    canvas.restore();
}
 
开发者ID:HowieTianDev,项目名称:ChenYan,代码行数:12,代码来源:CustomImageSpan.java

示例12: drawRightEdge

import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawRightEdge(DepthLayout dl, Canvas canvas, float[] src) {
    float[] dst = new float[]{dl.getTopRight().x, dl.getTopRight().y, dl.getTopRightBack().x, dl.getTopRightBack().y, dl.getBottomRightBack().x, dl.getBottomRightBack().y, dl.getBottomRight().x, dl.getBottomRight().y};
    int count = canvas.save();
    matrix.setPolyToPoly(src, 0, dst, 0, src.length >> 1);
    canvas.concat(matrix);
    drawRectancle(dl, canvas);
    drawShadow(dl.getTopRight(), dl.getBottomRight(), -180f, canvas, dl);
    canvas.restoreToCount(count);
}
 
开发者ID:MSay2,项目名称:Mire,代码行数:10,代码来源:DepthRendrer.java

示例13: draw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void draw(Canvas canvas) {
  canvas.save();
  canvas.concat(matrix);
  wrapped.draw(canvas);
  canvas.restore();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:FixedSizeDrawable.java

示例14: onDraw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    int bitmapWidth = bitmap.getWidth();
    int bitmapHeight = bitmap.getHeight();
    int centerX = getWidth() / 2;
    int centerY = getHeight() / 2;
    int x = centerX - bitmapWidth / 2;
    int y = centerY - bitmapHeight / 2;

    // 第一遍绘制:上半部分
    canvas.save();
    canvas.clipRect(0, 0, getWidth(), centerY);
    canvas.drawBitmap(bitmap, x, y, paint);
    canvas.restore();

    // 第二遍绘制:下半部分
    canvas.save();

    if (degree < 90) {
        canvas.clipRect(0, centerY, getWidth(), getHeight());
    } else {
        canvas.clipRect(0, 0, getWidth(), centerY);
    }
    camera.save();
    camera.rotateX(degree);
    canvas.translate(centerX, centerY);
    camera.applyToCanvas(canvas);
    canvas.translate(-centerX, -centerY);
    camera.restore();

    canvas.drawBitmap(bitmap, x, y, paint);
    canvas.restore();
}
 
开发者ID:TommyFen,项目名称:NaiveDemos,代码行数:36,代码来源:FlipboardView.java

示例15: drawItems

import android.graphics.Canvas; //导入方法依赖的package包/类
/**
 * Draws items
 *
 * @param canvas the canvas for drawing
 */
private void drawItems(Canvas canvas) {
    canvas.save();
    
    int top = (currentItem - firstItem) * getItemHeight() + (getItemHeight() - getHeight()) / 2;
    canvas.translate(PADDING, -top + scrollingOffset);
    
    itemsLayout.draw(canvas);
    
    canvas.restore();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:16,代码来源:WheelView.java


注:本文中的android.graphics.Canvas.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。