本文整理了Java中android.graphics.Shader.setLocalMatrix()
方法的一些代码示例,展示了Shader.setLocalMatrix()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Shader.setLocalMatrix()
方法的具体详情如下:
包路径:android.graphics.Shader
类名称:Shader
方法名:setLocalMatrix
暂无
代码示例来源:origin: koral--/android-gif-drawable
@Override
public void onDraw(Canvas canvas, Paint paint, Bitmap buffer) {
if (mCornerRadius == 0) {
canvas.drawBitmap(buffer, null, mDstRectF, paint);
return;
}
if (mShader == null) {
mShader = new BitmapShader(buffer, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
final Matrix shaderMatrix = new Matrix();
shaderMatrix.setTranslate(mDstRectF.left, mDstRectF.top);
shaderMatrix.preScale(mDstRectF.width() / buffer.getWidth(), mDstRectF.height() / buffer.getHeight());
mShader.setLocalMatrix(shaderMatrix);
}
paint.setShader(mShader);
canvas.drawRoundRect(mDstRectF, mCornerRadius, mCornerRadius, paint);
}
}
代码示例来源:origin: airbnb/lottie-android
@Override public void draw(Canvas canvas, Matrix parentMatrix, int parentAlpha) {
if (hidden) {
return;
}
L.beginSection("GradientFillContent#draw");
path.reset();
for (int i = 0; i < paths.size(); i++) {
path.addPath(paths.get(i).getPath(), parentMatrix);
}
path.computeBounds(boundsRect, false);
Shader shader;
if (type == GradientType.Linear) {
shader = getLinearGradient();
} else {
shader = getRadialGradient();
}
shaderMatrix.set(parentMatrix);
shader.setLocalMatrix(shaderMatrix);
paint.setShader(shader);
if (colorFilterAnimation != null) {
paint.setColorFilter(colorFilterAnimation.getValue());
}
int alpha = (int) ((parentAlpha / 255f * opacityAnimation.getValue() / 100f) * 255);
paint.setAlpha(clamp(alpha, 0, 255));
canvas.drawPath(path, paint);
L.endSection("GradientFillContent#draw");
}
代码示例来源:origin: alexvasilkov/GestureViews
private void updateShaderMatrix() {
if (!clipRect.isEmpty() && bitmapPaint.getShader() != null) {
getController().getState().get(tmpMatrix);
// Including paddings & reverting rotation (will be applied later in draw() method)
tmpMatrix.postTranslate(getPaddingLeft(), getPaddingTop());
tmpMatrix.postRotate(-clipRotation, clipRect.centerX(), clipRect.centerY());
bitmapPaint.getShader().setLocalMatrix(tmpMatrix);
}
}
代码示例来源:origin: jakob-grabner/Circle-Progress-View
private void setupBarPaint() {
if (mBarColors.length > 1) {
mBarPaint.setShader(new SweepGradient(mCircleBounds.centerX(), mCircleBounds.centerY(), mBarColors, null));
Matrix matrix = new Matrix();
mBarPaint.getShader().getLocalMatrix(matrix);
matrix.postTranslate(-mCircleBounds.centerX(), -mCircleBounds.centerY());
matrix.postRotate(mStartAngle);
matrix.postTranslate(mCircleBounds.centerX(), mCircleBounds.centerY());
mBarPaint.getShader().setLocalMatrix(matrix);
mBarPaint.setColor(mBarColors[0]);
} else if (mBarColors.length == 1) {
mBarPaint.setColor(mBarColors[0]);
mBarPaint.setShader(null);
} else {
mBarPaint.setColor(mBarColorStandard);
mBarPaint.setShader(null);
}
mBarPaint.setAntiAlias(true);
mBarPaint.setStrokeCap(mBarStrokeCap);
mBarPaint.setStyle(Style.STROKE);
mBarPaint.setStrokeWidth(mBarWidth);
if (mBarStrokeCap != Paint.Cap.BUTT) {
mShaderlessBarPaint = new Paint(mBarPaint);
mShaderlessBarPaint.setShader(null);
mShaderlessBarPaint.setColor(mBarColors[0]);
}
}
代码示例来源:origin: chiuki/advanced-textview
@Override
public void updateDrawState(TextPaint paint) {
paint.setStyle(Paint.Style.FILL);
Shader shader = new LinearGradient(0, 0, 0, paint.getTextSize() * colors.length, colors, null,
Shader.TileMode.MIRROR);
Matrix matrix = new Matrix();
matrix.setRotate(90);
shader.setLocalMatrix(matrix);
paint.setShader(shader);
}
}
代码示例来源:origin: chiuki/advanced-textview
@Override
public void updateDrawState(TextPaint paint) {
paint.setStyle(Paint.Style.FILL);
float width = paint.getTextSize() * colors.length;
if (shader == null) {
shader = new LinearGradient(0, 0, 0, width, colors, null,
Shader.TileMode.MIRROR);
}
matrix.reset();
matrix.setRotate(90);
matrix.postTranslate(width * translateXPercentage, 0);
shader.setLocalMatrix(matrix);
paint.setShader(shader);
}
}
代码示例来源:origin: zincPower/UI2018
public void init(Context context) {
Bitmap bm = Bitmap.createBitmap(new int[]{0xFFFFFFFF, 0xFFCCCCCC, 0xFFCCCCCC, 0xFFFFFFFF},
2, 2, Bitmap.Config.RGB_565);
itemBackground = new BitmapShader(bm,
Shader.TileMode.REPEAT,
Shader.TileMode.REPEAT);
Matrix m = new Matrix();
m.setScale(6, 6);
itemBackground.setLocalMatrix(m);
mBgPaint = new Paint();
mBitmapPaint = new Paint();
mBitmapPaint.setAntiAlias(true);
}
代码示例来源:origin: wcy10586/CustomShapeImageView
private void drawShader(Canvas canvas, Bitmap bmp, float bmpW, float bmpH, float w, float h) {
shader = new BitmapShader(bmp, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
Matrix matrix = new Matrix();
setMatrix(matrix, bmpW, bmpH, w, h);
shader.setLocalMatrix(matrix);
shaderPaint.setColor(Color.TRANSPARENT);
shaderPaint.setShader(shader);
canvas.drawPaint(shaderPaint);
}
代码示例来源:origin: qiubiteme/android_api_demos
public SampleView(Context context) {
super(context);
mSrcB = makeSrc(W, H);
mDstB = makeDst(W, H);
// make a ckeckerboard pattern
Bitmap bm = Bitmap.createBitmap(new int[] { 0xFFFFFFFF, 0xFFCCCCCC,
0xFFCCCCCC, 0xFFFFFFFF }, 2, 2,
Bitmap.Config.RGB_565);
mBG = new BitmapShader(bm,
Shader.TileMode.REPEAT,
Shader.TileMode.REPEAT);
Matrix m = new Matrix();
m.setScale(6, 6);
mBG.setLocalMatrix(m);
}
代码示例来源:origin: stackoverflow.com
int[] rainbow = getRainbowColors();
Shader shader = new LinearGradient(0, 0, 0, width, rainbow,
null, Shader.TileMode.REPEAT);
Matrix matrix = new Matrix();
matrix.setRotate(90);
shader.setLocalMatrix(matrix);
mPrimaryPaint.setShader(shader);
代码示例来源:origin: THEONE10211024/ApiDemos
public SampleView(Context context) {
super(context);
mSrcB = makeSrc(W, H);
mDstB = makeDst(W, H);
// make a ckeckerboard pattern
Bitmap bm = Bitmap.createBitmap(new int[] { 0xFFFFFFFF, 0xFFCCCCCC,
0xFFCCCCCC, 0xFFFFFFFF }, 2, 2,
Bitmap.Config.RGB_565);
mBG = new BitmapShader(bm,
Shader.TileMode.REPEAT,
Shader.TileMode.REPEAT);
Matrix m = new Matrix();
m.setScale(6, 6);
mBG.setLocalMatrix(m);
}
代码示例来源:origin: nomanr/android-image-magnifier
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (!zooming) {
buildDrawingCache();
} else {
bitmap = getDrawingCache();
shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
paint = new Paint();
paint.setShader(shader);
matrix.reset();
matrix.postScale(2f, 2f, zoomPos.x, zoomPos.y);
paint.getShader().setLocalMatrix(matrix);
canvas.drawCircle(zoomPos.x, zoomPos.y, sizeOfMagnifier, paint);
}
}
代码示例来源:origin: stackoverflow.com
public void init() {
int[] colors = {Color.GREEN, Color.RED};
float[] positions = {0, 1};
Matrix matrix = new Matrix();
matrix.postRotate(90, 100, 100);
Shader gradient = new SweepGradient(100, 100, colors, positions);
gradient.setLocalMatrix(matrix);
paint = new Paint();
paint.setShader(gradient);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawCircle(100, 100, 100, paint);
}
代码示例来源:origin: huangweicai/OkLibDemo
@Override
public void updateDrawState(TextPaint paint) {
paint.setStyle(Paint.Style.FILL);
Shader shader = new LinearGradient(0, 0, 0, paint.getTextSize() * colors.length, colors, null,
Shader.TileMode.MIRROR);
Matrix matrix = new Matrix();
matrix.setRotate(90);
shader.setLocalMatrix(matrix);
paint.setShader(shader);
}
}
代码示例来源:origin: Fueled/snippety
@Override
public void updateDrawState(TextPaint paint) {
paint.setStyle(Paint.Style.FILL);
float width = paint.getTextSize() * colors.length;
if (shader == null) {
shader = new LinearGradient(0, 0, 0, width, colors, null, Shader.TileMode.MIRROR);
}
matrix.reset();
matrix.setRotate(90);
matrix.postTranslate(width * translateXPercentage, 0);
shader.setLocalMatrix(matrix);
paint.setShader(shader);
}
}
代码示例来源:origin: THEONE10211024/ApiDemos
public SampleView(Context context) {
super(context);
setFocusable(true);
setFocusableInTouchMode(true);
mFastDF = new PaintFlagsDrawFilter(Paint.FILTER_BITMAP_FLAG |
Paint.DITHER_FLAG,
0);
mShader1 = new BitmapShader(makeBitmap1(), Shader.TileMode.REPEAT,
Shader.TileMode.REPEAT);
mShader2 = new BitmapShader(makeBitmap2(), Shader.TileMode.REPEAT,
Shader.TileMode.REPEAT);
Matrix m = new Matrix();
m.setRotate(30);
mShader2.setLocalMatrix(m);
mPaint = new Paint(Paint.FILTER_BITMAP_FLAG);
}
代码示例来源:origin: Fueled/snippety
@Override
public void updateDrawState(TextPaint paint) {
paint.setStyle(Paint.Style.FILL);
Shader shader = new LinearGradient(0, 0, 0, paint.getTextSize() * colors.length, colors, null,
Shader.TileMode.MIRROR);
Matrix matrix = new Matrix();
matrix.setRotate(angle);
shader.setLocalMatrix(matrix);
paint.setShader(shader);
}
}
代码示例来源:origin: jamorham/xDrip-plus
protected void updateRainbow() {
animationAngle = (animationAngle + 1) % 360;
//Animation matrix:
int[] rainbow = {Color.RED, Color.YELLOW, Color.GREEN, Color.BLUE
, Color.CYAN};
Shader shader = new LinearGradient(0, 0, 0, 20, rainbow,
null, Shader.TileMode.MIRROR);
Matrix matrix = new Matrix();
matrix.setRotate(animationAngle);
shader.setLocalMatrix(matrix);
mSgv.getPaint().setShader(shader);
invalidate();
}
代码示例来源:origin: huangweicai/OkLibDemo
@Override
public void updateDrawState(TextPaint paint) {
paint.setStyle(Paint.Style.FILL);
float width = paint.getTextSize() * colors.length;
if (shader == null) {
shader = new LinearGradient(0, 0, 0, width, colors, null,
Shader.TileMode.MIRROR);
}
matrix.reset();
matrix.setRotate(90);
matrix.postTranslate(width * translateXPercentage, 0);
shader.setLocalMatrix(matrix);
paint.setShader(shader);
}
}
代码示例来源:origin: zincPower/UI2018
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();
// 偏移
matrix.setTranslate(-x * FACTOR + RADIUS, -y * FACTOR + RADIUS);
shapeDrawable.getPaint().getShader().setLocalMatrix(matrix);
shapeDrawable.setBounds((int) x - RADIUS,
(int) y - RADIUS,
(int) x + RADIUS,
(int) y + RADIUS);
invalidate();
return true;
}
}
内容来源于网络,如有侵权,请联系作者删除!