當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。