當前位置: 首頁>>代碼示例>>Java>>正文


Java Canvas.MATRIX_SAVE_FLAG屬性代碼示例

本文整理匯總了Java中android.graphics.Canvas.MATRIX_SAVE_FLAG屬性的典型用法代碼示例。如果您正苦於以下問題:Java Canvas.MATRIX_SAVE_FLAG屬性的具體用法?Java Canvas.MATRIX_SAVE_FLAG怎麽用?Java Canvas.MATRIX_SAVE_FLAG使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在android.graphics.Canvas的用法示例。


在下文中一共展示了Canvas.MATRIX_SAVE_FLAG屬性的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: drawShade

/**
 * 畫遮罩效果
 *
 * @param canvas
 */
private void drawShade(Canvas canvas) {
    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);  //這裏要用個圖層,否則最後遮罩後其餘部分會黑
    float offX = currentPoint.getX();
    float offY = currentPoint.getY();
    int offSetX = (int) offX;
    int offSetY = (int) offY;
    int left_offSetY = 350 + (int) (offSetY * 0.3);                                         //左側圖Y方向移動距離
    int right_offSetX = (int) (200 - offSetX * 0.3);                                //右側圖X方向移動距離
    int right_offSetY = (int) (470 - offSetY * 0.3);                                //右側圖Y方向移動距離
    drawImage(canvas, mTotal_bitmap, 0, 0, width, height, 1471, 165);               //先畫底圖三角
    drawImage(canvas, mTotal_bitmap, 0, 0, width, height, 800, left_offSetY);       //繪製左邊的圖
    drawImage(canvas, mTotal_bitmap, 0, 0, width, height, right_offSetX, right_offSetY);
    path.reset();
    path.moveTo(0, 0);
    path.lineTo(width, 0);
    path.lineTo(width / 2, height);
    path.close();
    canvas.drawPath(path, mPaint_Mask);
    canvas.restore();
}
 
開發者ID:NickKJ,項目名稱:Mask-Animation,代碼行數:26,代碼來源:ShadeTriangleTotalForRankView.java

示例2: onDraw

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    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);  //這裏要用個圖層,否則最後遮罩後其餘部分會黑 (Here want to use a layer, or the last mask after the rest will be black.)
    path.reset();                                            //這行必須加,否則一直重複繪製 (This line must be added, or repeated drawing.)
    path.moveTo(0, 0);
    path.lineTo(width, 0);
    path.lineTo(width / 2, height);
    path.close();
    canvas.drawBitmap(mMask_bitmap, 0, 0, null);
    canvas.drawBitmap(mSource_one_bitmap, -100, anim_left_y, null);
    canvas.drawBitmap(mSource_two_bitmap, anim_right_x, anim_right_y, null);
    canvas.drawPath(path, mPaint_Mask);
    canvas.restore();

}
 
開發者ID:NickKJ,項目名稱:Mask-Animation,代碼行數:17,代碼來源:ShadeTriangleForRankView.java

示例3: onDraw

@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,代碼行數:28,代碼來源:ClipView.java

示例4: onDraw

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    int 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;
    int sc = canvas.saveLayer(0, 0, getWidth(), getHeight(), null, flags);

    int wg = mItemWidth + mItemGap;
    int x = (getWidth() - mWidth) / 2;
    int y = (getHeight() - mItemHeight) / 2;

    mItemDrawable.setBounds(0, 0, mItemWidth, mItemHeight);
    mItemDrawableSelected.setBounds(0, 0, mItemWidth, mItemHeight);

    for (int i = 0; i < mItemCount; i++) {
        canvas.save();
        canvas.translate(x + i * wg, y);
        mItemDrawable.draw(canvas);
        canvas.restore();
    }

    canvas.save();
    canvas.translate(x + (mPosition + mPositionOffset) * wg, y);
    mItemDrawableSelected.draw(canvas);
    canvas.restore();

    canvas.restoreToCount(sc);
}
 
開發者ID:czy1121,項目名稱:bannerview,代碼行數:28,代碼來源:ViewPagerIndicator.java

示例5: drawDrawable

/**
 * 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:turoDog,項目名稱:KTalk,代碼行數:40,代碼來源:EaseImageView.java

示例6: drawDrawable

private void drawDrawable(Canvas canvas, Bitmap bitmap) {
    // 畫筆
    Paint paint = new Paint();
    // 顏色設置
    paint.setColor(0xffffffff);
    // 抗鋸齒
    paint.setAntiAlias(true);
    //Paint 的 Xfermode,PorterDuff.Mode.SRC_IN 取兩層圖像的交集部門, 隻顯示上層圖像。
    PorterDuffXfermode xfermode = new PorterDuffXfermode(PorterDuff.Mode.SRC_IN);
    // 標誌
    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, mWidth, mHeight, null, saveFlags);

    if (mShapeType == 0) {
        // 畫遮罩,畫出來就是一個和空間大小相匹配的圓
        canvas.drawCircle(mWidth / 2, mHeight / 2, mWidth / 2, paint);
    } else {
        // 當ShapeType = 1 時 圖片為圓角矩形
        RectF rectf = new RectF(0, 0, getWidth(), getHeight());
        canvas.drawRoundRect(rectf, mRadius, mRadius, paint);
    }

    paint.setXfermode(xfermode);

    // 空間的大小 / bitmap 的大小 = bitmap 縮放的倍數
    float scaleWidth = ((float) getWidth()) / bitmap.getWidth();
    float scaleHeight = ((float) getHeight()) / bitmap.getHeight();

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

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

    //draw 上去
    canvas.drawBitmap(bitmap, 0, 0, paint);
    canvas.restore();
}
 
開發者ID:dufangyu1990,項目名稱:JKApp,代碼行數:42,代碼來源:MLImageView.java


注:本文中的android.graphics.Canvas.MATRIX_SAVE_FLAG屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。