本文整理汇总了Java中android.graphics.Shader.TileMode.CLAMP属性的典型用法代码示例。如果您正苦于以下问题:Java TileMode.CLAMP属性的具体用法?Java TileMode.CLAMP怎么用?Java TileMode.CLAMP使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.graphics.Shader.TileMode
的用法示例。
在下文中一共展示了TileMode.CLAMP属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createColorWheelBitmap
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
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: setBitmapShader
/**
* 设置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);
}
示例4: SelectableRoundedCornerDrawable
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);
}
示例5: setup
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: setUpShader
/**
* 初始化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);
}
示例7: createReflectionImageWithOrigin
public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap){
final int reflectionGap = 4;
int width = bitmap.getWidth();
int height = bitmap.getHeight();
Matrix matrix = new Matrix();
matrix.preScale(1, -1);
Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height/2, width, height/2, matrix, false);
Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height/2), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmapWithReflection);
canvas.drawBitmap(bitmap, 0, 0, null);
Paint deafalutPaint = new Paint();
canvas.drawRect(0, height,width,height + reflectionGap, deafalutPaint);
canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);
Paint paint = new Paint();
LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0, bitmapWithReflection.getHeight()
+ reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP);
paint.setShader(shader);
paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
canvas.drawRect(0, height, width, bitmapWithReflection.getHeight()
+ reflectionGap, paint);
return bitmapWithReflection;
}
示例8: createReflectionImageWithOrigin
/**
* 获得带倒影的图片方法
*
* @param bitmap 源图片
* @return 带倒影图片
*/
public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap) {
final int reflectionGap = 4;
int width = bitmap.getWidth();
int height = bitmap.getHeight();
Matrix matrix = new Matrix();
matrix.preScale(1, -1);
Bitmap reflectionImage = HSBitmapUtil.createBitmap(bitmap, 0,
height / 2, width, height / 2, matrix, false);
Bitmap bitmapWithReflection = HSBitmapUtil.createBitmap(width,
(height + height / 2), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmapWithReflection);
canvas.drawBitmap(bitmap, 0, 0, null);
Paint deafalutPaint = new Paint();
canvas.drawRect(0, height, width, height + reflectionGap, deafalutPaint);
canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);
Paint paint = new Paint();
LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0,
bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff,
0x00ffffff, TileMode.CLAMP);
paint.setShader(shader);
paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
canvas.drawRect(0, height, width, bitmapWithReflection.getHeight()
+ reflectionGap, paint);
return bitmapWithReflection;
}
示例9: generate
public GVRBitmapTexture generate(GVRContext context, int[] colors, float[] stops) {
Bitmap bitmap = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Shader shader = new LinearGradient(0,0, 0, HEIGHT,
colors, stops,
TileMode.CLAMP);
Paint paint = new Paint();
paint.setShader(shader);
canvas.drawRect(new Rect(0, 0, WIDTH, HEIGHT), paint);
GVRBitmapTexture texture = new GVRBitmapTexture(context, bitmap);
return texture;
}
示例10: drawAlphaPanel
private void drawAlphaPanel(Canvas canvas) {
if (!mShowAlphaPanel || mAlphaRect == null || mAlphaPattern == null) {
return;
}
final RectF rect = mAlphaRect;
if (BORDER_WIDTH_PX > 0) {
mBorderPaint.setColor(mBorderColor);
canvas.drawRect(rect.left - BORDER_WIDTH_PX,
rect.top - BORDER_WIDTH_PX,
rect.right + BORDER_WIDTH_PX,
rect.bottom + BORDER_WIDTH_PX,
mBorderPaint);
}
mAlphaPattern.draw(canvas);
float[] hsv = new float[] {
mHue, mSat, mVal
};
int color = Color.HSVToColor(hsv);
int acolor = Color.HSVToColor(0, hsv);
mAlphaShader = new LinearGradient(rect.left, rect.top, rect.right, rect.top,
color, acolor, TileMode.CLAMP);
mAlphaPaint.setShader(mAlphaShader);
canvas.drawRect(rect, mAlphaPaint);
if (mAlphaSliderText != null && mAlphaSliderText != "") {
canvas.drawText(mAlphaSliderText, rect.centerX(), rect.centerY() + 4 * mDensity,
mAlphaTextPaint);
}
float rectWidth = 4 * mDensity / 2;
Point p = alphaToPoint(mAlpha);
RectF r = new RectF();
r.left = p.x - rectWidth;
r.right = p.x + rectWidth;
r.top = rect.top - RECTANGLE_TRACKER_OFFSET;
r.bottom = rect.bottom + RECTANGLE_TRACKER_OFFSET;
canvas.drawRoundRect(r, 2, 2, mHueTrackerPaint);
}
示例11: setColor
public void setColor(int color) {
int[] colors = new int[] {
color,
color,
Color.argb(0, Color.red(color), Color.green(color),
Color.blue(color)) };
float[] points = new float[] { 0.0f, 1.0f, 1.0f };
points[points.length - 2] = lastPOint;
LinearGradient Lg = new LinearGradient(0, 2, 379, 2, colors, points,
TileMode.CLAMP);
Lg.setLocalMatrix(matrix);
P0.setShader(Lg);
}
示例12: draw
public void draw(@NonNull Canvas canvas) {
if (this.mRebuildShader) {
BitmapShader bitmapShader = new BitmapShader(this.mBitmap, this.mTileModeX, this
.mTileModeY);
if (this.mTileModeX == TileMode.CLAMP && this.mTileModeY == TileMode.CLAMP) {
bitmapShader.setLocalMatrix(this.mShaderMatrix);
}
this.mBitmapPaint.setShader(bitmapShader);
this.mRebuildShader = false;
}
if (this.mOval) {
if (this.mBorderWidth > 0.0f) {
canvas.drawOval(this.mDrawableRect, this.mBitmapPaint);
canvas.drawOval(this.mBorderRect, this.mBorderPaint);
return;
}
canvas.drawOval(this.mDrawableRect, this.mBitmapPaint);
} else if (any(this.mCornersRounded)) {
float radius = this.mCornerRadius;
if (this.mBorderWidth > 0.0f) {
canvas.drawRoundRect(this.mDrawableRect, radius, radius, this.mBitmapPaint);
canvas.drawRoundRect(this.mBorderRect, radius, radius, this.mBorderPaint);
redrawBitmapForSquareCorners(canvas);
redrawBorderForSquareCorners(canvas);
return;
}
canvas.drawRoundRect(this.mDrawableRect, radius, radius, this.mBitmapPaint);
redrawBitmapForSquareCorners(canvas);
} else {
canvas.drawRect(this.mDrawableRect, this.mBitmapPaint);
if (this.mBorderWidth > 0.0f) {
canvas.drawRect(this.mBorderRect, this.mBorderPaint);
}
}
}
示例13: RoundedDrawable
public RoundedDrawable(Bitmap bitmap, int cornerRadius, int margin) {
this.cornerRadius = (float) cornerRadius;
this.margin = margin;
this.bitmapShader = new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP);
this.mBitmapRect = new RectF((float) margin, (float) margin, (float) (bitmap.getWidth() - margin), (float) (bitmap.getHeight() - margin));
this.paint = new Paint();
this.paint.setAntiAlias(true);
this.paint.setShader(this.bitmapShader);
}
示例14: draw
public void draw(Canvas canvas) {
if (this.mRebuildShader) {
BitmapShader bitmapShader = new BitmapShader(this.mBitmap, this.mTileModeX, this.mTileModeY);
if (this.mTileModeX == TileMode.CLAMP && this.mTileModeY == TileMode.CLAMP) {
bitmapShader.setLocalMatrix(this.mShaderMatrix);
}
this.mBitmapPaint.setShader(bitmapShader);
this.mRebuildShader = false;
}
if (this.mOval) {
if (this.mBorderWidth > 0.0f) {
canvas.drawOval(this.mDrawableRect, this.mBitmapPaint);
canvas.drawOval(this.mBorderRect, this.mBorderPaint);
return;
}
canvas.drawOval(this.mDrawableRect, this.mBitmapPaint);
} else if (any(this.mCornersRounded)) {
float radius = this.mCornerRadius;
if (this.mBorderWidth > 0.0f) {
canvas.drawRoundRect(this.mDrawableRect, radius, radius, this.mBitmapPaint);
canvas.drawRoundRect(this.mBorderRect, radius, radius, this.mBorderPaint);
redrawBitmapForSquareCorners(canvas);
redrawBorderForSquareCorners(canvas);
return;
}
canvas.drawRoundRect(this.mDrawableRect, radius, radius, this.mBitmapPaint);
redrawBitmapForSquareCorners(canvas);
} else {
canvas.drawRect(this.mDrawableRect, this.mBitmapPaint);
if (this.mBorderWidth > 0.0f) {
canvas.drawRect(this.mBorderRect, this.mBorderPaint);
}
}
}
示例15: onBoundsChange
protected void onBoundsChange(Rect bounds) {
super.onBoundsChange(bounds);
RadialGradient vignette = new RadialGradient(this.mRect.centerX(), (this.mRect
.centerY() * 1.0f) / 0.7f, this.mRect.centerX() * 1.3f, new int[]{0, 0,
2130706432}, new float[]{0.0f, 0.7f, 1.0f}, TileMode.CLAMP);
Matrix oval = new Matrix();
oval.setScale(1.0f, 0.7f);
vignette.setLocalMatrix(oval);
this.paint.setShader(new ComposeShader(this.bitmapShader, vignette, Mode.SRC_OVER));
}