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


Java Canvas.saveLayer方法代码示例

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


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

示例1: onDraw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (progress == -1) {
        return;
    }

    float angle = (progress / 100f) * 360 - 90;
    float halfWidth = canvas.getWidth() / 2;
    float halfHeight = canvas.getHeight() / 2;
    progressRect.set(halfWidth * 0.75f, halfHeight * 0.75f, halfWidth * 1.25f, halfHeight * 1.25f);
    biggerRect.set(progressRect);
    int margin = 8;
    biggerRect.set(progressRect.left - margin, progressRect.top - margin, progressRect.right + margin, progressRect.bottom + margin);
    canvas.saveLayer(biggerRect, null, Canvas.ALL_SAVE_FLAG);
    canvas.drawOval(progressRect, circlePaint);
    canvas.drawArc(biggerRect, angle, 360 - angle - 90, true, clearPaint);
    canvas.restore();
}
 
开发者ID:Vavassor,项目名称:Tusky,代码行数:20,代码来源:ProgressImageView.java

示例2: createFramedPhoto

import android.graphics.Canvas; //导入方法依赖的package包/类
/**
 * @param x              图像的宽度
 * @param y              图像的高度
 * @param image          源图片
 * @param outerRadiusRat 圆角的大小
 * @return 圆角图片
 */
public static Bitmap createFramedPhoto(int x, int y, Bitmap image, float outerRadiusRat) {
    // 根据源文件新建一个darwable对象
    Drawable imageDrawable = new BitmapDrawable(image);

    // 新建一个新的输出图片
    Bitmap output = Bitmap.createBitmap(x, y, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    // 新建一个矩形
    RectF outerRect = new RectF(0, 0, x, y);

    // 产生一个红色的圆角矩形
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.RED);
    canvas.drawRoundRect(outerRect, outerRadiusRat, outerRadiusRat, paint);

    // 将源图片绘制到这个圆角矩形上
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    imageDrawable.setBounds(0, 0, x, y);
    canvas.saveLayer(outerRect, paint, Canvas.ALL_SAVE_FLAG);
    imageDrawable.draw(canvas);
    canvas.restore();

    return output;
}
 
开发者ID:starryxp,项目名称:LQRWeChat-master,代码行数:33,代码来源:ImageUtils.java

示例3: dispatchDraw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void dispatchDraw(Canvas canvas) {
    int saveCount = canvas.saveLayer(0, 0, getWidth(), getHeight(), null);
    super.dispatchDraw(canvas);

    int cornerWidth = mRoundedCornerBitmap.getWidth();
    int cornerHeight = mRoundedCornerBitmap.getHeight();
    // Clip top left corner.
    mMatrix.reset();
    canvas.drawBitmap(mRoundedCornerBitmap, mMatrix, mBackgroundClipPaint);
    // Clip top right corner.
    mMatrix.setRotate(90, cornerWidth / 2, cornerHeight / 2);
    mMatrix.postTranslate(canvas.getWidth() - cornerWidth, 0);
    canvas.drawBitmap(mRoundedCornerBitmap, mMatrix, mBackgroundClipPaint);
    // Clip bottom right corner.
    mMatrix.setRotate(180, cornerWidth / 2, cornerHeight / 2);
    mMatrix.postTranslate(canvas.getWidth() - cornerWidth, canvas.getHeight() - cornerHeight);
    canvas.drawBitmap(mRoundedCornerBitmap, mMatrix, mBackgroundClipPaint);
    // Clip bottom left corner.
    mMatrix.setRotate(270, cornerWidth / 2, cornerHeight / 2);
    mMatrix.postTranslate(0, canvas.getHeight() - cornerHeight);
    canvas.drawBitmap(mRoundedCornerBitmap, mMatrix, mBackgroundClipPaint);

    canvas.restoreToCount(saveCount);
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:26,代码来源:PopupItemView.java

示例4: drawBitmap

import android.graphics.Canvas; //导入方法依赖的package包/类
/**
     * 绘制图片
     *
     * @param point  单位点
     * @param radius 半径
     * @param bitmap 图片
     * @param canvas 画布
     * @param paint  画笔
     */
    private void drawBitmap(Point point, int radius, Bitmap bitmap, Canvas canvas, Paint paint) {
        // 判断mGestureLockView开启了动画
        if (mGestureLockView.isUseAnim()) {
            RectF rectF = new RectF(point.x - mGestureLockView.getRadius(), point.y - mGestureLockView.getRadius(), point.x + mGestureLockView.getRadius(), point.y + mGestureLockView.getRadius());
            int index = canvas.saveLayer(rectF, paint, Canvas.ALL_SAVE_FLAG);
            canvas.drawCircle(point.x, point.y, radius, paint);
            paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
            canvas.drawBitmap(bitmap, point.x - mGestureLockView.getRadius(), point.y - mGestureLockView.getRadius(), paint);
            paint.setXfermode(null);
            canvas.restoreToCount(index);
        } else {
            canvas.drawBitmap(bitmap, point.x - radius, point.y - radius, null);
        }
//        canvas.drawBitmap(Bitmap.createScaledBitmap(bitmap, radius * 2, radius * 2, false), point.x - radius, point.y - radius, null);
    }
 
开发者ID:sinawangnan7,项目名称:GestureLockView,代码行数:25,代码来源:Painter.java

示例5: onDraw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
    protected void onDraw(Canvas canvas) {
        int canvasWidth = canvas.getWidth();
        int canvasHeight = canvas.getHeight();
        int layerId = canvas.saveLayer(0, 0, canvasWidth, canvasHeight, null, Canvas.ALL_SAVE_FLAG);
        {
            bgPaint.setColor(bgColor);
            // draw the background of progress
            canvas.drawRoundRect(bgRect, rectRadius, rectRadius, bgPaint);
            // draw progress
            canvas.drawRect(progressRect, progressPaint);
            bgPaint.setXfermode(null);
            if (bitmap != null) {
                //draw icon
                canvas.drawBitmap(bitmap, srcRect, dstRect, bgPaint);
            }
        }
        canvas.restoreToCount(layerId);
        // TODO: 弄明白为什么在xml预览中,canvas.restoreToCount
        // TODO: 会导致后续的canvas对象为空 但canvas.restore方法则不会导致这个问题
//        canvas.restore();
//        canvas.save();

    }
 
开发者ID:CuiZhaoHui,项目名称:IOS11RectProgress,代码行数:25,代码来源:RectProgress.java

示例6: drawProgressRectWithXfermode

import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawProgressRectWithXfermode(Canvas canvas) {
    mPaint.setStyle(Paint.Style.FILL);
    //根据进度比率计算出当前的进度值对应的宽度
    int progress = (int) (mValidWidth * (getProgress() * 1.0f / getMax()));
    int layer = canvas.saveLayer(0, 0, progress, getHeight(), null, Canvas.ALL_SAVE_FLAG);
    canvas.translate(getPaddingLeft(), getPaddingTop());
    drawRoundRectPath();
    mPaint.setColor(mProgressBarColor);
    canvas.drawPath(mRoundRectPath, mPaint);
    drawProgressPath(progress);
    mPaint.setXfermode(mXfermode);
    canvas.drawPath(mProgressPath, mPaint);
    canvas.restoreToCount(layer);
    mPaint.setXfermode(null);

}
 
开发者ID:guzhigang001,项目名称:Bailan,代码行数:17,代码来源:DownloadProgressButton.java

示例7: onDraw

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

    int layerId = canvas.saveLayer(0, 0, getWidth(), getHeight(), null, Canvas.ALL_SAVE_FLAG);

    //先把手指轨迹画到目标Bitmap上
    Canvas c = new Canvas(BmpDST);
    c.drawPath(mPath,mBitPaint);

    //然后把目标图像画到画布上
    canvas.drawBitmap(BmpDST,0,0,mBitPaint);

    //计算源图像区域
    mBitPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(BmpSRC,0,0,mBitPaint);

    mBitPaint.setXfermode(null);
    canvas.restoreToCount(layerId);
}
 
开发者ID:halohoop,项目名称:AndroidDigIn,代码行数:21,代码来源:EraserView_SRCOUT.java

示例8: dispatchDraw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void dispatchDraw(Canvas canvas) {
    int saveCount = canvas.saveLayer(0, 0, getWidth(), getHeight(), null, Canvas.ALL_SAVE_FLAG);

    super.dispatchDraw(canvas);

    paint.setXfermode(pdMode);
    canvas.drawPath(clipPath, paint);

    canvas.restoreToCount(saveCount);
    paint.setXfermode(null);
}
 
开发者ID:HanyeeWang,项目名称:GeekZone,代码行数:13,代码来源:DiagonalLayout.java

示例9: onDraw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
    mDrawable.draw(canvas);
    int sc = canvas.saveLayer(mCenterRect.left, mCenterRect.top,
            mCenterRect.right, mCenterRect.bottom,
            null, Canvas.ALL_SAVE_FLAG);
    canvas.drawRect(mProgressRect, mPaint);
    mPaint.setXfermode(mXfermodeDstIn);
    canvas.drawBitmap(mBitmap, mCenterRect.left, mCenterRect.top, mPaint);
    mPaint.setXfermode(null);
    canvas.restoreToCount(sc);
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:13,代码来源:RefreshLayout.java

示例10: onDraw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas paramCanvas) {
    if (useDefaultStyle) {
        super.onDraw(paramCanvas);
        return;
    }
    final Drawable localDrawable = getDrawable();
    if (localDrawable == null)
        return;
    if (localDrawable instanceof NinePatchDrawable) {
        return;
    }
    if (this.paint == null) {
        final Paint localPaint = new Paint();
        localPaint.setFilterBitmap(false);
        localPaint.setAntiAlias(true);
        localPaint.setXfermode(MASK_XFERMODE);
        this.paint = localPaint;
    }
    final int width = getWidth();
    final int height = getHeight();
    /** 保存layer */
    int layer = paramCanvas.saveLayer(0.0F, 0.0F, width, height, null, 31);
    /** 设置drawable的大小 */
    localDrawable.setBounds(0, 0, width, height);
    /** 将drawable绑定到bitmap(this.mask)上面(drawable只能通过bitmap显示出来) */
    localDrawable.draw(paramCanvas);
    if ((this.mask == null) || (this.mask.isRecycled())) {
        this.mask = createOvalBitmap(width, height);
    }
    /** 将bitmap画到canvas上面 */
    paramCanvas.drawBitmap(this.mask, 0.0F, 0.0F, this.paint);
    /** 将画布复制到layer上 */
    paramCanvas.restoreToCount(layer);
    drawBorder(paramCanvas, width, height);
}
 
开发者ID:lzmlsfe,项目名称:19porn,代码行数:37,代码来源:CircleImageView.java

示例11: drawDrawable

import android.graphics.Canvas; //导入方法依赖的package包/类
/**
 * draw Rounded Rectangle
 *
 * @param canvas
 * @param bitmap
 */
private void drawDrawable(Canvas canvas, Bitmap bitmap) {
    Paint paint = new Paint();
    paint.setColor(0xffffffff);
    paint.setAntiAlias(true); //smooths out the edges of what is being drawn
    PorterDuffXfermode xfermode = new PorterDuffXfermode(PorterDuff.Mode.SRC_IN);
    // set flags
    int saveFlags = Canvas.MATRIX_SAVE_FLAG
            | Canvas.CLIP_SAVE_FLAG
            | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG
            | Canvas.FULL_COLOR_LAYER_SAVE_FLAG
            | Canvas.CLIP_TO_LAYER_SAVE_FLAG;
    canvas.saveLayer(0, 0, width, height, null, saveFlags);

    if (shapeType == 1) {
        canvas.drawCircle(width / 2, height / 2, width / 2 - 1, paint);
    } else if (shapeType == 2) {
        RectF rectf = new RectF(1, 1, getWidth() - 1, getHeight() - 1);
        canvas.drawRoundRect(rectf, radius + 1, radius + 1, paint);
    }

    paint.setXfermode(xfermode);

    float scaleWidth = ((float) getWidth()) / bitmap.getWidth();
    float scaleHeight = ((float) getHeight()) / bitmap.getHeight();

    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);

    //bitmap scale
    bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);

    canvas.drawBitmap(bitmap, 0, 0, paint);
    canvas.restore();
}
 
开发者ID:Vicent9920,项目名称:FanChat,代码行数:41,代码来源:EaseImageView.java

示例12: onDraw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    int saveCount = canvas.saveLayer(0, 0, getWidth(), getHeight(), null, Canvas.ALL_SAVE_FLAG);
    drawLoading(canvas, mAnimateValue * DEGREE_PER_LINE);
    canvas.restoreToCount(saveCount);
}
 
开发者ID:QMUI,项目名称:QMUI_Android,代码行数:8,代码来源:QMUILoadingView.java

示例13: onDraw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    int LAYER_FLAGS = Canvas.MATRIX_SAVE_FLAG | Canvas.CLIP_SAVE_FLAG
            | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG
            | Canvas.CLIP_TO_LAYER_SAVE_FLAG;
    //通过Xfermode的DST_OUT来产生中间的透明裁剪区域,一定要另起一个Layer(层)
    canvas.saveLayer(0, 0, this.getWidth(), this.getHeight(), null, LAYER_FLAGS);
    //设置背景
    canvas.drawColor(Color.parseColor("#a8000000"));
    paint.setXfermode(xfermode);
    //绘制圆形裁剪框
    if (clipType == ClipType.CIRCLE) {
        //中间的透明的圆
        canvas.drawCircle(this.getWidth() / 2, this.getHeight() / 2, clipRadiusWidth, paint);
        //白色的圆边框
        canvas.drawCircle(this.getWidth() / 2, this.getHeight() / 2, clipRadiusWidth, borderPaint);
    } else if (clipType == ClipType.RECTANGLE) { //绘制矩形裁剪框
        //绘制中间的矩形
        canvas.drawRect(mHorizontalPadding, this.getHeight() / 2 - clipWidth / 2,
                this.getWidth() - mHorizontalPadding, this.getHeight() / 2 + clipWidth / 2, paint);
        //绘制白色的矩形边框
        canvas.drawRect(mHorizontalPadding, this.getHeight() / 2 - clipWidth / 2,
                this.getWidth() - mHorizontalPadding, this.getHeight() / 2 + clipWidth / 2, borderPaint);
    }
    //出栈,恢复到之前的图层,意味着新建的图层会被删除,新建图层上的内容会被绘制到canvas (or the previous layer)
    canvas.restore();
}
 
开发者ID:Horrarndoo,项目名称:YiZhi,代码行数:29,代码来源:ClipView.java

示例14: dispatchDraw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void dispatchDraw(Canvas canvas) {
	int saveCount = canvas.saveLayer(0, 0, getWidth(), getHeight(), null, Canvas.ALL_SAVE_FLAG);

	super.dispatchDraw(canvas);

	paint.setXfermode(pdMode);
	canvas.drawPath(clipPath, paint);

	canvas.restoreToCount(saveCount);
	paint.setXfermode(null);
}
 
开发者ID:drakeet,项目名称:WeiboFixer,代码行数:13,代码来源:DiagonalLayout.java

示例15: draw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void draw(Canvas canvas, Matrix parentMatrix, int parentAlpha) {
  if (!visible) {
    return;
  }
  buildParentLayerListIfNeeded();
  matrix.reset();
  matrix.set(parentMatrix);
  for (int i = parentLayers.size() - 1; i >= 0; i--) {
    matrix.preConcat(parentLayers.get(i).transform.getMatrix());
  }
  matrix.preConcat(transform.getMatrix());
  int alpha = (int)
      ((parentAlpha / 255f * (float) transform.getOpacity().getValue() / 100f) * 255);
  if (!hasMatteOnThisLayer() && !hasMasksOnThisLayer()) {
    drawLayer(canvas, matrix, alpha);
    return;
  }

  // TODO: make sure this is the right clip.
  rect.set(canvas.getClipBounds());
  canvas.saveLayer(rect, contentPaint, Canvas.ALL_SAVE_FLAG);
  // Clear the off screen buffer. This is necessary for some phones.
  canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), clearPaint);
  drawLayer(canvas, matrix, alpha);

  if (hasMasksOnThisLayer()) {
    applyMasks(canvas, matrix);
  }

  if (hasMatteOnThisLayer()) {
    canvas.saveLayer(rect, mattePaint, SAVE_FLAGS);
    canvas.drawRect(rect, clearPaint);
    //noinspection ConstantConditions
    matteLayer.draw(canvas, parentMatrix, alpha);
    canvas.restore();
  }

  canvas.restore();
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:41,代码来源:BaseLayer.java


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