Java Code Examples for android.graphics.Shader.TileMode#CLAMP
The following examples show how to use
android.graphics.Shader.TileMode#CLAMP .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RLImgUtil.java From Roid-Library with Apache License 2.0 | 6 votes |
/** * @param bitmap * @return */ public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap) { final int reflectionGap = 4; int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix matrix = new Matrix(); matrix.preScale(1, -1); Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, h / 2, w, h / 2, matrix, false); Bitmap bitmapWithReflection = Bitmap.createBitmap(w, (h + h / 2), Config.ARGB_8888); Canvas canvas = new Canvas(bitmapWithReflection); canvas.drawBitmap(bitmap, 0, 0, null); Paint deafalutPaint = new Paint(); canvas.drawRect(0, h, w, h + reflectionGap, deafalutPaint); canvas.drawBitmap(reflectionImage, 0, h + reflectionGap, null); Paint paint = new Paint(); LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0, bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP); paint.setShader(shader); // Set the Transfer mode to be porter duff and destination in paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); // Draw a rectangle using the paint with our linear gradient canvas.drawRect(0, h, w, bitmapWithReflection.getHeight() + reflectionGap, paint); return bitmapWithReflection; }
Example 2
Source File: AmbilWarnaKotak.java From callmeter with GNU General Public License v3.0 | 6 votes |
@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); }
Example 3
Source File: ColorPicker.java From px-android with MIT License | 6 votes |
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[] = { 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; }
Example 4
Source File: PXLinearGradient.java From pixate-freestyle-android with Apache License 2.0 | 6 votes |
private LinearGradient getGradient(PointF point1, PointF point2) { adjustGradientColors(); int[] colors = new int[this.colors.size()]; for (int i = 0; i < colors.length; i++) { colors[i] = this.colors.get(i); } float[] positions = null; if (!offsets.isEmpty()) { positions = new float[this.offsets.size()]; for (int i = 0; i < positions.length; i++) { positions[i] = this.offsets.get(i); } } try { LinearGradient gradient = new LinearGradient(point1.x, point1.y, point2.x, point2.y, colors, positions, TileMode.CLAMP); return gradient; } catch (Exception e) { if (PXLog.isLogging()) { PXLog.e(TAG, e, "Error while instantiating a LinearGradient"); } return null; } }
Example 5
Source File: ShrinkingTextView.java From commcare-android with Apache License 2.0 | 6 votes |
@Override public void draw(Canvas canvas) { super.draw(canvas); if (mInteractive && !mExpanded || isAnimating()) { Rect r = new Rect(); this.getDrawingRect(r); Paint p = new Paint(); float f = this.getTextSize(); int px = (int)(f / 2); int bottom = r.bottom - this.getPaddingBottom(); int top = bottom - px; int start = Color.argb(0, 255, 255, 255); int end = Color.argb(220, 255, 255, 255); Shader shader = new LinearGradient(r.left, top, r.left, bottom, start, end, TileMode.CLAMP); p.setShader(shader); r.set(r.left, top, r.right, bottom); p.setStyle(Paint.Style.FILL); canvas.drawRect(r, p); } }
Example 6
Source File: CircleImageView.java From the-tech-frontier-app with MIT License | 6 votes |
/** * 初始化BitmapShader */ private void setUpShader() { Drawable drawable = getDrawable(); if (drawable == null) { return; } Bitmap bmp = drawableToBitamp(drawable); // 将bmp作为着色器,就是在指定区域内绘制bmp mBitmapShader = new BitmapShader(bmp, TileMode.CLAMP, TileMode.CLAMP); float scale = 1.0f; // 拿到bitmap宽或高的小值 int bSize = Math.min(bmp.getWidth(), bmp.getHeight()); scale = mWidth * 1.0f / bSize; // shader的变换矩阵,我们这里主要用于放大或者缩小 mMatrix.setScale(scale, scale); // 设置变换矩阵 mBitmapShader.setLocalMatrix(mMatrix); // 设置shader mBitmapPaint.setShader(mBitmapShader); }
Example 7
Source File: ColorPicker.java From SystemBarTint with Apache License 2.0 | 6 votes |
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; }
Example 8
Source File: RoundedImageView.java From letv with Apache License 2.0 | 5 votes |
private static TileMode parseTileMode(int tileMode) { switch (tileMode) { case 0: return TileMode.CLAMP; case 1: return TileMode.REPEAT; case 2: return TileMode.MIRROR; default: return null; } }
Example 9
Source File: RoundedVignetteBitmapDisplayer.java From letv with Apache License 2.0 | 5 votes |
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)); }
Example 10
Source File: XBitmapUtils.java From XFrame with Apache License 2.0 | 5 votes |
/** * 获得带倒影的Bitmap * * @param bitmap 源Bitmap * @return 带倒影的Bitmap */ public static Bitmap createReflectionBitmap(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); // Set the Transfer mode to be porter duff and destination in paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); // Draw a rectangle using the paint with our linear gradient canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint); return bitmapWithReflection; }
Example 11
Source File: ColorsHelper.java From Stayfit with Apache License 2.0 | 5 votes |
public void setGradientPaint(Paint paint, float left, float top, float right, float bottom, int[] colors2) { LinearGradient linearGradient = new LinearGradient(left, top, right, bottom, colors2, null, TileMode.CLAMP); paint.setShader(linearGradient); paint.setAntiAlias(true); }
Example 12
Source File: RoundImageView.java From orz with Apache License 2.0 | 5 votes |
/** * 初始化BitmapShader */ private void setUpShader() { Drawable drawable = getDrawable(); if (drawable == null) { return; } Bitmap bmp = drawableToBitmap(drawable); // 将bmp作为着色器,就是在指定区域内绘制bmp mBitmapShader = new BitmapShader(bmp, TileMode.CLAMP, TileMode.CLAMP); float scale = 1.0f; if (mType == TYPE_CIRCLE) { // 拿到bitmap宽或高的小值 int bSize = Math.min(bmp.getWidth(), bmp.getHeight()); scale = mWidth * 1.0f / bSize; } else if (mType == TYPE_ROUND) { // 如果图片的宽或者高与view的宽高不匹配,计算出需要缩放的比例;缩放后的图片的宽高,一定要大于我们view的宽高;所以我们这里取大值; scale = Math.max(getWidth() * 1.0f / bmp.getWidth(), getHeight() * 1.0f / bmp.getHeight()); } // shader的变换矩阵,我们这里主要用于放大或者缩小 mMatrix.setScale(scale, scale); // 设置变换矩阵 mBitmapShader.setLocalMatrix(mMatrix); // 设置shader mBitmapPaint.setShader(mBitmapShader); }
Example 13
Source File: CircleBitmapDisplayer.java From Android-Application-ZJB with Apache License 2.0 | 5 votes |
public CircleDrawable(Bitmap bitmap) { this.bitmapShader = new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP); this.mBitmapRect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); this.paint = new Paint(); this.paint.setAntiAlias(true); this.paint.setShader(this.bitmapShader); }
Example 14
Source File: ImageUtils.java From monolog-android with MIT License | 5 votes |
/** * 获得带�?�影的图片方�? * * @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 = 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); // Set the Transfer mode to be porter duff and destination in paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); // Draw a rectangle using the paint with our linear gradient canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint); return bitmapWithReflection; }
Example 15
Source File: DetailAnimViewGroup.java From ListItemFold with MIT License | 5 votes |
protected void prepareFold() { this.polygonFlat = new float[8]; this.polygonFlat[0] = 0.0f; this.polygonFlat[1] = 0.0f; this.polygonFlat[2] = 0.0f; this.polygonFlat[5] = 0.0f; this.polygonFolded = new float[8]; this.firstShadowGradientPaint = new Paint(); this.firstShadowGradientPaint.setStyle(Style.FILL); this.secondShadowGradientPaint = new Paint(); this.secondShadowGradientPaint.setStyle(Style.FILL); this.foldLinePaint = new Paint(); this.foldLinePaint.setStrokeWidth(getResources().getDisplayMetrics().density * 2.0f); this.foldLinePaint.setColor(-1); this.foldLinePaint.setAlpha(0); int height = Math.round(((float) getMeasuredHeight()) / 2.0f); LinearGradient firstShadowGradient = new LinearGradient(0.0f, 0.0f, 0.0f, (float) height, 0x3f000000, 0xbb000000, TileMode.CLAMP); LinearGradient secondShadowGradient = new LinearGradient(0.0f, 0.0f, 0.0f, (float) height, 0xbb000000, 0, TileMode.CLAMP); this.firstShadowGradientPaint.setShader(firstShadowGradient); this.secondShadowGradientPaint.setShader(secondShadowGradient); this.firstHalfRect = new Rect(); this.secondHalfRect = new Rect(); this.firstHalfMatrix = new Matrix(); this.secondHalfMatrix = new Matrix(); this.firstHalfRect = new Rect(0, 0, getMeasuredWidth(), Math.round(((float) getMeasuredHeight()) / 2.0f)); this.secondHalfRect = new Rect(0, Math.round(((float) getMeasuredHeight()) / 2.0f), getMeasuredWidth(), getMeasuredHeight()); this.halfPageHeight = (int) Math.ceil((double) (((float) getMeasuredHeight()) / 2.0f)); this.halfPageWidth = getMeasuredWidth(); this.prepared = true; calculateMatrix(true); calculateMatrix(false); }
Example 16
Source File: ClockFaceView.java From material-components-android with Apache License 2.0 | 5 votes |
private RadialGradient getGradientForTextView(RectF selectorBox, RectF tvBox) { if (!RectF.intersects(selectorBox, tvBox)) { return null; } return new RadialGradient( (selectorBox.centerX() - scratch.left), (selectorBox.centerY() - scratch.top), selectorBox.width() * .5f, gradientColors, gradientPositions, TileMode.CLAMP); }
Example 17
Source File: ImageViewPlus.java From BaseProject with Apache License 2.0 | 4 votes |
@Override protected void onDraw(Canvas canvas) { Bitmap rawBitmap = getBitmap(getDrawable()); if (rawBitmap != null && mType != TYPE_NONE){ int viewWidth = getWidth(); int viewHeight = getHeight(); int viewMinSize = Math.min(viewWidth, viewHeight); float dstWidth = mType == TYPE_CIRCLE ? viewMinSize : viewWidth; float dstHeight = mType == TYPE_CIRCLE ? viewMinSize : viewHeight; float halfBorderWidth = mBorderWidth / 2.0f; float doubleBorderWidth = mBorderWidth * 2; if (mShader == null || !rawBitmap.equals(mRawBitmap)){ mRawBitmap = rawBitmap; mShader = new BitmapShader(mRawBitmap, TileMode.CLAMP, TileMode.CLAMP); } if (mShader != null) { mMatrix.setScale((dstWidth - doubleBorderWidth) / rawBitmap.getWidth(), (dstHeight - doubleBorderWidth) / rawBitmap.getHeight()); mShader.setLocalMatrix(mMatrix); } mPaintBitmap.setShader(mShader); mPaintBorder.setStyle(Paint.Style.STROKE); mPaintBorder.setStrokeWidth(mBorderWidth); mPaintBorder.setColor(mBorderWidth > 0 ? mBorderColor : Color.TRANSPARENT); if (mType == TYPE_CIRCLE){ float radius = viewMinSize / 2.0f; canvas.drawCircle(radius, radius, radius - halfBorderWidth, mPaintBorder); canvas.translate(mBorderWidth, mBorderWidth); canvas.drawCircle(radius - mBorderWidth, radius - mBorderWidth, radius - mBorderWidth, mPaintBitmap); } else if (mType == TYPE_ROUNDED_RECT){ mRectBorder.set(halfBorderWidth, halfBorderWidth, dstWidth - halfBorderWidth, dstHeight - halfBorderWidth); mRectBitmap.set(0.0f, 0.0f, dstWidth - doubleBorderWidth, dstHeight - doubleBorderWidth); float borderRadius = mRectRoundRadius - halfBorderWidth > 0.0f ? mRectRoundRadius - halfBorderWidth : 0.0f; float bitmapRadius = mRectRoundRadius - mBorderWidth > 0.0f ? mRectRoundRadius - mBorderWidth : 0.0f; canvas.drawRoundRect(mRectBorder, borderRadius, borderRadius, mPaintBorder); canvas.translate(mBorderWidth, mBorderWidth); canvas.drawRoundRect(mRectBitmap, bitmapRadius, bitmapRadius, mPaintBitmap); } } else { super.onDraw(canvas); } }
Example 18
Source File: ColorPickerView.java From HomeGenie-Android with GNU General Public License v3.0 | 4 votes |
private void drawAlphaPanel(Canvas canvas) { /* * Will be drawn with hw acceleration, very fast. */ 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.equals("")){ 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, mHueAlphaTrackerPaint); }
Example 19
Source File: ColorPickerView.java From Atomic with GNU General Public License v3.0 | 4 votes |
private void drawAlphaPanel(Canvas canvas) { /* * Will be drawn with hw acceleration, very fast. */ 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.equals("")){ 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, mHueAlphaTrackerPaint); }
Example 20
Source File: ColorPickerView.java From Hangar with GNU General Public License v3.0 | 2 votes |
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); }