本文整理汇总了Java中android.graphics.Canvas.CLIP_SAVE_FLAG属性的典型用法代码示例。如果您正苦于以下问题:Java Canvas.CLIP_SAVE_FLAG属性的具体用法?Java Canvas.CLIP_SAVE_FLAG怎么用?Java Canvas.CLIP_SAVE_FLAG使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.graphics.Canvas
的用法示例。
在下文中一共展示了Canvas.CLIP_SAVE_FLAG属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: 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();
}
示例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();
}
示例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);
}
示例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();
}
示例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();
}