本文整理汇总了Java中android.graphics.Shader.TileMode类的典型用法代码示例。如果您正苦于以下问题:Java TileMode类的具体用法?Java TileMode怎么用?Java TileMode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TileMode类属于android.graphics.Shader包,在下文中一共展示了TileMode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createColorWheelBitmap
import android.graphics.Shader.TileMode; //导入依赖的package包/类
private Bitmap createColorWheelBitmap(int width, int height) {
Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
int colorCount = 12;
int colorAngleStep = 360 / 12;
int colors[] = new int[colorCount + 1];
float hsv[] = new float[] { 0f, 1f, 1f };
for (int i = 0; i < colors.length; i++) {
hsv[0] = (i * colorAngleStep + 180) % 360;
colors[i] = Color.HSVToColor(hsv);
}
colors[colorCount] = colors[0];
SweepGradient sweepGradient = new SweepGradient(width / 2, height / 2, colors, null);
RadialGradient radialGradient = new RadialGradient(width / 2, height / 2, colorWheelRadius, 0xFFFFFFFF, 0x00FFFFFF, TileMode.CLAMP);
ComposeShader composeShader = new ComposeShader(sweepGradient, radialGradient, PorterDuff.Mode.SRC_OVER);
colorWheelPaint.setShader(composeShader);
Canvas canvas = new Canvas(bitmap);
canvas.drawCircle(width / 2, height / 2, colorWheelRadius, colorWheelPaint);
return bitmap;
}
示例2: createColorDiscBitmap
import android.graphics.Shader.TileMode; //导入依赖的package包/类
private Bitmap createColorDiscBitmap(int radius) {
int centerColor, edgeColor;
Bitmap bitmap = Bitmap.createBitmap(2 * radius, 2 * radius, Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
mHSV[0] = 0; mHSV[1] = 1; mHSV[2] = 1; //red
SweepGradient sweepGradient = new SweepGradient(radius, radius, getColors(mHSV), null);
mColorPaint.setShader(sweepGradient);
canvas.drawCircle(radius, radius, radius, mColorPaint);
mHSV[0] = 0; mHSV[1] = 0; mHSV[2] = 1; //white
centerColor = Color.HSVToColor(255, mHSV);
edgeColor = Color.HSVToColor(0, mHSV);
RadialGradient radialGradient = new RadialGradient(radius, radius, radius, centerColor, edgeColor, TileMode.CLAMP);
mColorPaint.setShader(radialGradient);
canvas.drawCircle(radius, radius, radius, mColorPaint);
return bitmap;
}
示例3: drawColorSquare
import android.graphics.Shader.TileMode; //导入依赖的package包/类
private void drawColorSquare(Canvas canvas) {
int pureColor, brightColor, darkColor, transparentColor;
// pureColor
mHSV[0] = mColorHSV[0];
mHSV[1] = 1; mHSV[2] = 1;
pureColor = Color.HSVToColor(mHSV);
// brightColor
mHSV[1] = 0; mHSV[2] = 1;
brightColor = Color.HSVToColor(mHSV);
// darkColor
mHSV[1] = 1; mHSV[2] = 0;
darkColor = Color.HSVToColor(255, mHSV);
// alphaColor
mHSV[1] = 0; mHSV[2] = 0;
transparentColor = Color.HSVToColor(0, mHSV);
// drawn without compose shader, but looks worse
Shader gradient1 = new LinearGradient(mSquareRect.right, mSquareRect.bottom, mSquareRect.right, mSquareRect.top, brightColor, pureColor, TileMode.CLAMP);
Shader gradient2 = new LinearGradient(mSquareRect.right, mSquareRect.bottom, mSquareRect.left, mSquareRect.bottom, transparentColor, darkColor, TileMode.CLAMP);
mColorPaint.setShader(gradient1);
canvas.drawRect(mSquareRect, mColorPaint);
mColorPaint.setShader(gradient2);
canvas.drawRect(mSquareRect, mColorPaint);
}
示例4: transform
import android.graphics.Shader.TileMode; //导入依赖的package包/类
public Bitmap transform(Bitmap source) {
int size = Math.min(source.getWidth(), source.getHeight());
Bitmap squaredBitmap = Bitmap.createBitmap(source, (source.getWidth() - size) / 2, (source.getHeight() - size) / 2, size, size);
if (squaredBitmap != source) {
source.recycle();
}
Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setShader(new BitmapShader(squaredBitmap, TileMode.CLAMP, TileMode.CLAMP));
paint.setAntiAlias(true);
float r = ((float) size) / 2.0f;
canvas.drawCircle(r, r, r, paint);
squaredBitmap.recycle();
return bitmap;
}
示例5: setup
import android.graphics.Shader.TileMode; //导入依赖的package包/类
private void setup() {
if (!this.mReady) {
this.mSetupPending = true;
} else if (this.mBitmap != null) {
this.mBitmapShader = new BitmapShader(this.mBitmap, TileMode.CLAMP, TileMode.CLAMP);
this.mBitmapPaint.setAntiAlias(true);
this.mBitmapPaint.setShader(this.mBitmapShader);
this.mBorderPaint.setStyle(Style.STROKE);
this.mBorderPaint.setAntiAlias(true);
this.mBorderPaint.setColor(this.mBorderColor);
this.mBorderPaint.setStrokeWidth((float) this.mBorderWidth);
this.mBitmapHeight = this.mBitmap.getHeight();
this.mBitmapWidth = this.mBitmap.getWidth();
this.mBorderRect.set(0.0f, 0.0f, (float) getWidth(), (float) getHeight());
this.mBorderRadius = Math.min((this.mBorderRect.height() - ((float) this.mBorderWidth)) / 2.0f, (this.mBorderRect.width() - ((float) this.mBorderWidth)) / 2.0f);
this.mDrawableRect.set((float) this.mBorderWidth, (float) this.mBorderWidth, this.mBorderRect.width() - ((float) this.mBorderWidth), this.mBorderRect.height() - ((float) this.mBorderWidth));
this.mDrawableRadius = Math.min(this.mDrawableRect.height() / 2.0f, this.mDrawableRect.width() / 2.0f);
updateShaderMatrix();
invalidate();
}
}
示例6: CircleDrawable
import android.graphics.Shader.TileMode; //导入依赖的package包/类
public CircleDrawable(Bitmap bitmap, Integer strokeColor, float strokeWidth) {
this.radius = (float) (Math.min(bitmap.getWidth(), bitmap.getHeight()) / 2);
this.bitmapShader = new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP);
this.mBitmapRect = new RectF(0.0f, 0.0f, (float) bitmap.getWidth(), (float) bitmap
.getHeight());
this.paint = new Paint();
this.paint.setAntiAlias(true);
this.paint.setShader(this.bitmapShader);
this.paint.setFilterBitmap(true);
this.paint.setDither(true);
if (strokeColor == null) {
this.strokePaint = null;
} else {
this.strokePaint = new Paint();
this.strokePaint.setStyle(Style.STROKE);
this.strokePaint.setColor(strokeColor.intValue());
this.strokePaint.setStrokeWidth(strokeWidth);
this.strokePaint.setAntiAlias(true);
}
this.strokeWidth = strokeWidth;
this.strokeRadius = this.radius - (strokeWidth / 2.0f);
}
示例7: SelectableRoundedCornerDrawable
import android.graphics.Shader.TileMode; //导入依赖的package包/类
public SelectableRoundedCornerDrawable(Bitmap bitmap, Resources r) {
this.mBitmap = bitmap;
this.mBitmapShader = new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP);
if (bitmap != null) {
this.mBitmapWidth = bitmap.getScaledWidth(r.getDisplayMetrics());
this.mBitmapHeight = bitmap.getScaledHeight(r.getDisplayMetrics());
} else {
this.mBitmapHeight = -1;
this.mBitmapWidth = -1;
}
this.mBitmapRect.set(0.0f, 0.0f, (float) this.mBitmapWidth, (float) this.mBitmapHeight);
this.mBitmapPaint = new Paint(1);
this.mBitmapPaint.setStyle(Style.FILL);
this.mBitmapPaint.setShader(this.mBitmapShader);
this.mBorderPaint = new Paint(1);
this.mBorderPaint.setStyle(Style.STROKE);
this.mBorderPaint.setColor(this.mBorderColor.getColorForState(getState(), -16777216));
this.mBorderPaint.setStrokeWidth(this.mBorderWidth);
}
示例8: buildShadowCorners
import android.graphics.Shader.TileMode; //导入依赖的package包/类
private void buildShadowCorners() {
RectF innerBounds = new RectF(-this.mCornerRadius, -this.mCornerRadius, this.mCornerRadius, this.mCornerRadius);
RectF outerBounds = new RectF(innerBounds);
outerBounds.inset(-this.mShadowSize, -this.mShadowSize);
if (this.mCornerShadowPath == null) {
this.mCornerShadowPath = new Path();
} else {
this.mCornerShadowPath.reset();
}
this.mCornerShadowPath.setFillType(FillType.EVEN_ODD);
this.mCornerShadowPath.moveTo(-this.mCornerRadius, 0.0f);
this.mCornerShadowPath.rLineTo(-this.mShadowSize, 0.0f);
this.mCornerShadowPath.arcTo(outerBounds, 180.0f, 90.0f, false);
this.mCornerShadowPath.arcTo(innerBounds, 270.0f, -90.0f, false);
this.mCornerShadowPath.close();
float startRatio = this.mCornerRadius / (this.mCornerRadius + this.mShadowSize);
this.mCornerShadowPaint.setShader(new RadialGradient(0.0f, 0.0f, this.mCornerRadius + this.mShadowSize, new int[]{this.mShadowStartColor, this.mShadowStartColor, this.mShadowEndColor}, new float[]{0.0f, startRatio, 1.0f}, TileMode.CLAMP));
this.mEdgeShadowPaint.setShader(new LinearGradient(0.0f, (-this.mCornerRadius) + this.mShadowSize, 0.0f, (-this.mCornerRadius) - this.mShadowSize, new int[]{this.mShadowStartColor, this.mShadowStartColor, this.mShadowEndColor}, new float[]{0.0f, 0.5f, 1.0f}, TileMode.CLAMP));
this.mEdgeShadowPaint.setAntiAlias(false);
}
示例9: buildShadowCorners
import android.graphics.Shader.TileMode; //导入依赖的package包/类
private void buildShadowCorners() {
RectF innerBounds = new RectF(-this.mCornerRadius, -this.mCornerRadius, this.mCornerRadius, this.mCornerRadius);
RectF outerBounds = new RectF(innerBounds);
outerBounds.inset(-this.mShadowSize, -this.mShadowSize);
if (this.mCornerShadowPath == null) {
this.mCornerShadowPath = new Path();
} else {
this.mCornerShadowPath.reset();
}
this.mCornerShadowPath.setFillType(FillType.EVEN_ODD);
this.mCornerShadowPath.moveTo(-this.mCornerRadius, 0.0f);
this.mCornerShadowPath.rLineTo(-this.mShadowSize, 0.0f);
this.mCornerShadowPath.arcTo(outerBounds, 180.0f, 90.0f, false);
this.mCornerShadowPath.arcTo(innerBounds, 270.0f, -90.0f, false);
this.mCornerShadowPath.close();
float shadowRadius = -outerBounds.top;
if (shadowRadius > 0.0f) {
float startRatio = this.mCornerRadius / shadowRadius;
float midRatio = startRatio + ((1.0f - startRatio) / 2.0f);
this.mCornerShadowPaint.setShader(new RadialGradient(0.0f, 0.0f, shadowRadius, new int[]{0, this.mShadowStartColor, this.mShadowMiddleColor, this.mShadowEndColor}, new float[]{0.0f, startRatio, midRatio, 1.0f}, TileMode.CLAMP));
}
this.mEdgeShadowPaint.setShader(new LinearGradient(0.0f, innerBounds.top, 0.0f, outerBounds.top, new int[]{this.mShadowStartColor, this.mShadowMiddleColor, this.mShadowEndColor}, new float[]{0.0f, SHADOW_HORIZ_SCALE, 1.0f}, TileMode.CLAMP));
this.mEdgeShadowPaint.setAntiAlias(false);
}
示例10: setBitmapShader
import android.graphics.Shader.TileMode; //导入依赖的package包/类
/**
* 设置BitmapShader
*/
private void setBitmapShader() {
Drawable drawable = getDrawable();
if (null == drawable) {
return;
}
Bitmap bitmap = drawableToBitmap(drawable);
// 将bitmap作为着色器来创建一个BitmapShader
mBitmapShader = new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP);
float scale = 1.0f;
if (mType == TYPE_CIRCLE) {
// 拿到bitmap宽或高的小值
int bSize = Math.min(bitmap.getWidth(), bitmap.getHeight());
scale = mWidth * 1.0f / bSize;
} else if (mType == TYPE_ROUND || mType == TYPE_OVAL) {
// 如果图片的宽或者高与view的宽高不匹配,计算出需要缩放的比例;缩放后的图片的宽高,一定要大于我们view的宽高;所以我们这里取大值;
scale = Math.max(getWidth() * 1.0f / bitmap.getWidth(), getHeight() * 1.0f / bitmap.getHeight());
}
// shader的变换矩阵,我们这里主要用于放大或者缩小
mMatrix.setScale(scale, scale);
// 设置变换矩阵
mBitmapShader.setLocalMatrix(mMatrix);
mPaint.setShader(mBitmapShader);
}
示例11: onDraw
import android.graphics.Shader.TileMode; //导入依赖的package包/类
@SuppressLint("DrawAllocation")
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
int width = getMeasuredWidth();
int height = getMeasuredHeight();
int new_color = Color.HSVToColor(hsv);
if(color != new_color)
{
Shader shader_x = new LinearGradient(0.0F, 0.0F, width, 0.0F, Color.WHITE, new_color, TileMode.CLAMP);
ComposeShader shader = new ComposeShader(shader_y, shader_x, PorterDuff.Mode.MULTIPLY);
paint.setShader(shader);
color = new_color;
}
canvas.drawRect(0.0F, 0.0F, width, height, paint);
}
示例12: createColorWheelBitmap
import android.graphics.Shader.TileMode; //导入依赖的package包/类
private Bitmap createColorWheelBitmap(int width, int height) {
Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
int colorCount = 12;
int colorAngleStep = 360 / 12;
int colors[] = new int[colorCount + 1];
float hsv[] = new float[]{0f, 1f, 1f};
for (int i = 0; i < colors.length; i++) {
hsv[0] = (i * colorAngleStep + 180) % 360;
colors[i] = Color.HSVToColor(hsv);
}
colors[colorCount] = colors[0];
SweepGradient sweepGradient = new SweepGradient(width / 2, height / 2, colors, null);
RadialGradient radialGradient = new RadialGradient(width / 2, height / 2, colorWheelRadius, 0xFFFFFFFF, 0x00FFFFFF, TileMode.CLAMP);
ComposeShader composeShader = new ComposeShader(sweepGradient, radialGradient, PorterDuff.Mode.SRC_OVER);
colorWheelPaint.setShader(composeShader);
Canvas canvas = new Canvas(bitmap);
canvas.drawCircle(width / 2, height / 2, colorWheelRadius, colorWheelPaint);
return bitmap;
}
示例13: onDraw
import android.graphics.Shader.TileMode; //导入依赖的package包/类
@Override
protected void onDraw(final Canvas canvas) {
super.onDraw(canvas);
if (this.paint == null) {
this.paint = new Paint();
this.luar = new LinearGradient(0.f, 0.f, 0.f, this.ukuranUiPx, 0xffffffff, 0xff000000,
TileMode.CLAMP);
}
this.tmp00[1] = this.tmp00[2] = 1.f;
this.tmp00[0] = this.hue;
int rgb = Color.HSVToColor(this.tmp00);
this.dalam = new LinearGradient(0.f, 0.f, this.ukuranUiPx, 0.f, 0xffffffff, rgb,
TileMode.CLAMP);
ComposeShader shader = new ComposeShader(this.luar, this.dalam, PorterDuff.Mode.MULTIPLY);
this.paint.setShader(shader);
canvas.drawRect(0.f, 0.f, this.ukuranUiPx, this.ukuranUiPx, this.paint);
}
示例14: createReflectedImage
import android.graphics.Shader.TileMode; //导入依赖的package包/类
/**
* 全倒影
*
* @param originalImage
* @return
*/
public static Bitmap createReflectedImage(Bitmap originalImage, int imageHeight) {
int width = originalImage.getWidth();
int height = originalImage.getHeight();
Matrix matrix = new Matrix();
matrix.preScale(1, -1);
Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, height - imageHeight, width, imageHeight, matrix, false);
Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + imageHeight), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmapWithReflection);
Paint defaultpPaint = new Paint();
canvas.drawBitmap(originalImage, 0, 0, defaultpPaint);
canvas.drawBitmap(reflectionImage, 0, height, defaultpPaint);
Paint paint = new Paint();
LinearGradient shader = new LinearGradient(0, originalImage.getHeight(), 0, bitmapWithReflection.getHeight(), 0x70ffffff, 0x00ffffff, TileMode.MIRROR);
paint.setShader(shader);
paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
canvas.drawRect(0, height, width, bitmapWithReflection.getHeight(), paint);
reflectionImage.recycle();
return bitmapWithReflection;
}
示例15: setUpShader
import android.graphics.Shader.TileMode; //导入依赖的package包/类
/**
* 初始化BitmapShader
*/
private void setUpShader()
{
Drawable drawable = getDrawable();
if (drawable == null)
{
Log.e("view", "ok");
return;
}
Bitmap bmp = drawableToBitamp(drawable);
// 将bmp作为着色器,就是在指定区域内绘制bmp
mBitmapShader = new BitmapShader(bmp, TileMode.CLAMP, TileMode.CLAMP);
float scale = 1.0f;
int bSize = Math.min(bmp.getWidth(), bmp.getHeight());
scale = getWidth() * 1.0f / bSize;
// shader的变换矩阵,我们这里主要用于放大或者缩小
matrix.setScale(scale, scale);
// 设置变换矩阵
mBitmapShader.setLocalMatrix(matrix);
// 设置shader
paint.setShader(mBitmapShader);
}