android.graphics.BitmapShader Java Examples
The following examples show how to use
android.graphics.BitmapShader.
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: GlideLoaderProcessor.java From ImageLoaderProcessor with Apache License 2.0 | 6 votes |
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) { if (source == null){ return null; } int size = Math.min(source.getWidth(), source.getHeight()); int x = (source.getWidth() - size) / 2; int y = (source.getHeight() - size) / 2; Bitmap squared = Bitmap.createBitmap(source, x, y, size, size); Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888); if (result == null) { result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(result); Paint paint = new Paint(); paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); paint.setAntiAlias(true); float r = size / 2f; canvas.drawCircle(r, r, r, paint); return result; }
Example #2
Source File: GlideRoundTransform.java From AssistantBySDK with Apache License 2.0 | 6 votes |
private static Bitmap roundCrop(BitmapPool pool, Bitmap source) { if (source == null) return null; Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); if (result == null) { result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(result); Paint paint = new Paint(); paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); paint.setAntiAlias(true); RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight()); canvas.drawRoundRect(rectF, radius, radius, paint); return result; }
Example #3
Source File: Service.java From Twire with GNU General Public License v3.0 | 6 votes |
public static void setTopRounded(Bitmap workingBitmap, float cornerRadius) { int w = workingBitmap.getWidth(); int h = workingBitmap.getHeight(); Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(bmp); Shader shader = new BitmapShader(workingBitmap, Shader.TileMode.MIRROR, Shader.TileMode.MIRROR); Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG); paint.setAntiAlias(true); paint.setShader(shader); RectF rec = new RectF(0, 0, w, h - (h / 3)); c.drawRect(new RectF(0, (h / 3), w, h), paint); c.drawRoundRect(rec, cornerRadius, cornerRadius, paint); //v.setImageDrawable(new BitmapDrawable(context.getResources(), bmp)); //v.setImageBitmap(new BitmapDrawable(context.getResources(), bmp).getBitmap()); }
Example #4
Source File: RoundedTopTransformation.java From Twire with GNU General Public License v3.0 | 6 votes |
@Override protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) { int w = toTransform.getWidth(); int h = toTransform.getHeight(); Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(bmp); Shader shader = new BitmapShader(toTransform, Shader.TileMode.MIRROR, Shader.TileMode.MIRROR); Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG); paint.setAntiAlias(true); paint.setShader(shader); RectF rec = new RectF(0, 0, w, h - (h / 3)); c.drawRect(new RectF(0, (h / 3), w, h), paint); c.drawRoundRect(rec, cornerRadius, cornerRadius, paint); toTransform.recycle(); return bmp; }
Example #5
Source File: BaseAppWidget.java From RetroMusicPlayer with GNU General Public License v3.0 | 6 votes |
protected static Bitmap createRoundedBitmap(Drawable drawable, int width, int height, float tl, float tr, float bl, float br) { if (drawable == null) return null; Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(bitmap); drawable.setBounds(0, 0, width, height); drawable.draw(c); Bitmap rounded = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(rounded); Paint paint = new Paint(); paint.setShader(new BitmapShader(bitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); paint.setAntiAlias(true); canvas.drawPath(composeRoundedRectPath(new RectF(0, 0, width, height), tl, tr, bl, br), paint); return rounded; }
Example #6
Source File: CircleTransform.java From Moment with GNU General Public License v3.0 | 6 votes |
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) { if (source == null) return null; int size = Math.min(source.getWidth(), source.getHeight()); int x = (source.getWidth() - size) / 2; int y = (source.getHeight() - size) / 2; Bitmap squared = Bitmap.createBitmap(source, x, y, size, size); Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888); if (result == null) { result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(result); Paint paint = new Paint(); paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); paint.setAntiAlias(true); float r = size / 2f; canvas.drawCircle(r, r, r, paint); squared.recycle(); return result; }
Example #7
Source File: BubbleImageView.java From LQRWeChat with MIT License | 6 votes |
private void setup() { if (mBitmap == null) { return; } mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); mBitmapPaint = new Paint(); mBitmapPaint.setAntiAlias(true); mBitmapPaint.setShader(mBitmapShader); mBitmapHeight = mBitmap.getHeight(); mBitmapWidth = mBitmap.getWidth(); updateShaderMatrix(); invalidate(); }
Example #8
Source File: GlideRoundedTransform.java From Alibaba-Android-Certification with MIT License | 6 votes |
private Bitmap roundCrop(BitmapPool pool, Bitmap source) { if (source == null) return null; Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); if (result == null) { result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(result); Paint paint = new Paint(); paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); paint.setAntiAlias(true); RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight()); canvas.drawRoundRect(rectF, radius, radius, paint); return result; }
Example #9
Source File: GlideCircleTransform.java From Aurora with Apache License 2.0 | 6 votes |
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) { if (source == null) return null; int size = Math.min(source.getWidth(), source.getHeight()); int x = (source.getWidth() - size) / 2; int y = (source.getHeight() - size) / 2; // TODO this could be acquired from the pool too Bitmap squared = Bitmap.createBitmap(source, x, y, size, size); Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888); if (result == null) { result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(result); Paint paint = new Paint(); paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); paint.setAntiAlias(true); float r = size / 2f; canvas.drawCircle(r, r, r, paint); return result; }
Example #10
Source File: CircleTransformation.java From AcgClub with MIT License | 6 votes |
private Bitmap circleCrop(BitmapPool pool, Bitmap source) { if (source == null) { return null; } int size = Math.min(source.getWidth(), source.getHeight()); int x = (source.getWidth() - size) / 2; int y = (source.getHeight() - size) / 2; // TODO this could be acquired from the pool too Bitmap squared = Bitmap.createBitmap(source, x, y, size, size); Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888); if (result == null) { result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(result); Paint paint = new Paint(); paint.setShader( new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); paint.setAntiAlias(true); float r = size / 2f; canvas.drawCircle(r, r, r, paint); return result; }
Example #11
Source File: RoundedCornersTransformation.java From AcgClub with MIT License | 6 votes |
@Override protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) { int width = toTransform.getWidth(); int height = toTransform.getHeight(); Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888); bitmap.setHasAlpha(true); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setShader(new BitmapShader(toTransform, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)); drawRoundRect(canvas, paint, width, height); return bitmap; }
Example #12
Source File: GlideRoundTransformUtil.java From youqu_master with Apache License 2.0 | 6 votes |
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) { if (source == null) return null; int size = Math.min(source.getWidth(), source.getHeight()); int x = (source.getWidth() - size) / 2; int y = (source.getHeight() - size) / 2; // TODO this could be acquired from the pool too Bitmap squared = Bitmap.createBitmap(source, x, y, size, size); Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888); if (result == null) { result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(result); Paint paint = new Paint(); paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); paint.setAntiAlias(true); float r = size / 2f; canvas.drawCircle(r, r, r, paint); return result; }
Example #13
Source File: BorderRoundTransformation.java From ImageLoader with Apache License 2.0 | 6 votes |
@Override public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) { Bitmap source = resource.get(); int width = source.getWidth(); int height = source.getHeight(); Bitmap bitmap = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888); if (bitmap == null) { bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(bitmap);//新建一个空白的bitmap Paint paint = new Paint(); paint.setAntiAlias(true); paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));//设置要绘制的图形 Paint borderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);//设置边框样式 borderPaint.setColor(mBorderColor); borderPaint.setStyle(Paint.Style.STROKE); borderPaint.setStrokeWidth(mBorderWidth); drawRoundRect(canvas, paint, width, height, borderPaint); return BitmapResource.obtain(bitmap, mBitmapPool); }
Example #14
Source File: GlideCircleTransform.java From DMusic with Apache License 2.0 | 6 votes |
@Override protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { if (toTransform == null) { return null; } Bitmap result = pool.get(outWidth, outHeight, Bitmap.Config.ARGB_8888); int size = Math.min(toTransform.getWidth(), toTransform.getHeight()); int x = (toTransform.getWidth() - size) / 2; int y = (toTransform.getHeight() - size) / 2; float out = outWidth; float scale = out / size; mMatrix.reset(); mMatrix.postScale(scale, scale); Bitmap squared = Bitmap.createBitmap(toTransform, x, y, size, size, mMatrix, true); if (result == null) { result = Bitmap.createBitmap(outWidth, outHeight, Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(result); Paint paint = new Paint(); paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); paint.setAntiAlias(true); float r = out / 2f; canvas.drawCircle(r, r, r - 1, paint); squared.recycle(); return result; }
Example #15
Source File: GlideTransformUtils.java From DevUtils with Apache License 2.0 | 6 votes |
private Bitmap roundCrop(BitmapPool pool, Bitmap source) { if (source == null) return null; Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_4444); if (result == null) { result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_4444); } Canvas canvas = new Canvas(result); Paint paint = new Paint(); paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); paint.setAntiAlias(true); RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight()); canvas.drawRoundRect(rectF, radius, radius, paint); return result; }
Example #16
Source File: GlideRoundTransform.java From Android with MIT License | 6 votes |
private Bitmap roundCrop(BitmapPool pool, Bitmap source) { if (source == null) return null; Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); if (result == null) { result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(result); Paint paint = new Paint(); paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); paint.setAntiAlias(true); RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight()); canvas.drawRoundRect(rectF, radius, radius, paint); Log.e("11aa", radius + ""); return result; }
Example #17
Source File: BubbleImageView.java From Tok-Android with GNU General Public License v3.0 | 6 votes |
private void setup() { if (mBitmap == null) { return; } mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); mBitmapPaint = new Paint(); mBitmapPaint.setAntiAlias(true); mBitmapPaint.setShader(mBitmapShader); mBitmapHeight = mBitmap.getHeight(); mBitmapWidth = mBitmap.getWidth(); updateShaderMatrix(); invalidate(); }
Example #18
Source File: GlideRoundTransform.java From Common with Apache License 2.0 | 6 votes |
@Override protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { if (toTransform == null) { return null; } Bitmap result = pool.get(outWidth, outHeight, Bitmap.Config.ARGB_8888); int size = Math.min(toTransform.getWidth(), toTransform.getHeight()); int x = (toTransform.getWidth() - size) / 2; int y = (toTransform.getHeight() - size) / 2; float out = outWidth; float scale = out / size; mMatrix.reset(); mMatrix.postScale(scale, scale); Bitmap squared = Bitmap.createBitmap(toTransform, x, y, size, size, mMatrix, true); if (result == null) { result = Bitmap.createBitmap(outWidth, outHeight, Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(result); Paint paint = new Paint(); paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); paint.setAntiAlias(true); RectF rect = new RectF(1, 1, out - 1, out - 1); canvas.drawRoundRect(rect, mRadius, mRadius, paint); squared.recycle(); return result; }
Example #19
Source File: HoldingButton.java From HoldingButton with Apache License 2.0 | 6 votes |
public void setCancelIcon(@Nullable Bitmap bitmap) { if (bitmap != null) { mCancelIconWidth = bitmap.getWidth(); mCancelIconHeight = bitmap.getHeight(); mCancelIconShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); mCancelIconShader.setLocalMatrix(mCancelIconMatrix); mCancelIconPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mCancelIconPaint.setShader(mCancelIconShader); mCancelIconPaint.setColorFilter(new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN)); invalidate(); } else { mCancelIconWidth = 0; mCancelIconHeight = 0; mCancelIconMatrix = null; mCancelIconPaint = null; } }
Example #20
Source File: BaseAppWidget.java From Music-Player with GNU General Public License v3.0 | 6 votes |
protected static Bitmap createRoundedBitmap(Drawable drawable, int width, int height, float tl, float tr, float bl, float br) { if (drawable == null) return null; Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(bitmap); drawable.setBounds(0, 0, width, height); drawable.draw(c); Bitmap rounded = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(rounded); Paint paint = new Paint(); paint.setShader(new BitmapShader(bitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); paint.setAntiAlias(true); canvas.drawPath(composeRoundedRectPath(new RectF(0, 0, width, height), tl, tr, bl, br), paint); return rounded; }
Example #21
Source File: GlideRoundTransform.java From PoetryWeather with Apache License 2.0 | 6 votes |
private Bitmap roundCrop(BitmapPool pool, Bitmap source) { if (source == null) return null; Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); if (result == null) { result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(result); Paint paint = new Paint(); paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); paint.setAntiAlias(true); RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight()); canvas.drawRoundRect(rectF, radius, radius, paint); return result; }
Example #22
Source File: GlideCircleTransform.java From XFrame with Apache License 2.0 | 6 votes |
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) { if (source == null) return null; int size = Math.min(source.getWidth(), source.getHeight()); int x = (source.getWidth() - size) / 2; int y = (source.getHeight() - size) / 2; Bitmap squared = Bitmap.createBitmap(source, x, y, size, size); Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888); if (result == null) { result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(result); Paint paint = new Paint(); paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); paint.setAntiAlias(true); float r = size / 2f; canvas.drawCircle(r, r, r, paint); return result; }
Example #23
Source File: ShapeImageView.java From SimpleProject with MIT License | 6 votes |
@Override protected void onDraw(Canvas canvas) { Drawable drawable = getDrawable(); if (drawable == null) { super.onDraw(canvas); } Bitmap bitmap = BitmapUtil.drawableToBitmap(drawable); if (bitmap == null) { return; } BitmapShader bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setShader(bitmapShader); RectF rect = new RectF(0, 0, getWidth(), getHeight()); int radius = Math.min(getWidth(), getHeight()) / 2; if (mShape == SHAPE_TYPE_CIRCLE) { canvas.drawCircle(radius, radius, radius, paint); } else if (mShape == SHAPE_TYPE_ROUND) { canvas.drawRoundRect(rect, mRadius, mRadius, paint); } }
Example #24
Source File: RoundedCornersTransformation2.java From ImageLoader with Apache License 2.0 | 6 votes |
public Bitmap transform(Bitmap source, int outWidth, int outHeight) { int width = source.getWidth(); int height = source.getHeight(); Bitmap bitmap = Bitmap.createBitmap(width, height, source.getConfig()); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)); drawRoundRect(canvas, paint, width, height); //source.recycle(); return bitmap; }
Example #25
Source File: BaseAppWidget.java From MusicPlayer with GNU General Public License v3.0 | 6 votes |
protected static Bitmap createRoundedBitmap(Drawable drawable, int width, int height, float tl, float tr, float bl, float br) { if (drawable == null) return null; Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(bitmap); drawable.setBounds(0, 0, width, height); drawable.draw(c); Bitmap rounded = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(rounded); Paint paint = new Paint(); paint.setShader(new BitmapShader(bitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); paint.setAntiAlias(true); canvas.drawPath(composeRoundedRectPath(new RectF(0, 0, width, height), tl, tr, bl, br), paint); return rounded; }
Example #26
Source File: CircleGlide.java From Cook-It-Android-XML-Template with MIT License | 6 votes |
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) { if (source == null) return null; int size = Math.min(source.getWidth(), source.getHeight()); int x = (source.getWidth() - size) / 2; int y = (source.getHeight() - size) / 2; // TODO this could be acquired from the pool too Bitmap squared = Bitmap.createBitmap(source, x, y, size, size); Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888); if (result == null) { result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(result); Paint paint = new Paint(); paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); paint.setAntiAlias(true); float r = size / 2f; canvas.drawCircle(r, r, r, paint); return result; }
Example #27
Source File: AFGlideUtil.java From AFBaseLibrary with Apache License 2.0 | 6 votes |
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) { if (source == null) { return null; } else { int size = Math.min(source.getWidth(), source.getHeight()); int x = (source.getWidth() - size) / 2; int y = (source.getHeight() - size) / 2; Bitmap squared = Bitmap.createBitmap(source, x, y, size, size); Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888); if (result == null) { result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(result); Paint paint = new Paint(); paint.setShader(new BitmapShader(squared, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)); paint.setAntiAlias(true); float r = (float) size / 2.0F; canvas.drawCircle(r, r, r, paint); return result; } }
Example #28
Source File: CircleTransform.java From eternity with Apache License 2.0 | 6 votes |
@Override public Bitmap transform(Bitmap source) { final Paint paint = new Paint(); paint.setAntiAlias(true); paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)); Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); canvas.drawRoundRect(new RectF(margin, margin, source.getWidth() - margin, source.getHeight() - margin), radius, radius, paint); if (source != output) { source.recycle(); } return output; }
Example #29
Source File: BubbleDrawable.java From BubbleView with Apache License 2.0 | 6 votes |
public BubbleDrawable(Builder builder) { triangleWidth = builder.triangleWidth; triangleHeight = builder.triangleHeight; offset = builder.offset; radius = builder.radius; orientation = builder.orientation; bitmap = builder.bitmap; borderWidth = builder.borderWidth; centerArrow = builder.centerArrow; shadowRadius = builder.shadowRadius; shadowColor = builder.shadowColor; borderPaint.setStyle(Paint.Style.STROKE); borderPaint.setStrokeCap(Paint.Cap.ROUND); borderPaint.setColor(builder.borderColor); leftTopRadiusRect = new RectF(); rightBottomRadiusRect = new RectF(); leftBottomRadiusRect = new RectF(); rightTopRadiusRect = new RectF(); bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); bitmapPaint.setShader(bitmapShader); }
Example #30
Source File: RadialGradientRippleView.java From AndroidDigIn with Apache License 2.0 | 6 votes |
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mScaledBitmap = Bitmap.createScaledBitmap(mOriBitmap, w, h, true); mRippleScaledBitmap = Bitmap.createScaledBitmap(mOriBitmap, (int) (w * RIPPLE_SCALE_FACTOR), (int) (h * RIPPLE_SCALE_FACTOR), true); int width1 = mScaledBitmap.getWidth(); int height1 = mScaledBitmap.getHeight(); int width2 = mRippleScaledBitmap.getWidth(); int height2 = mRippleScaledBitmap.getHeight(); mDisW = Math.abs(width1 - width2) / 2; mDisH = Math.abs(height1 - height2) / 2;//算出两图中点相聚的距离,就是放大后需要矫正的位移距离 mOriBitmap.recycle(); mOriBitmap = null; //这里的模式无所谓,因为在屏幕外看不到 mBitmapShader = new BitmapShader(mRippleScaledBitmap, Shader.TileMode.MIRROR,//这里的模式无所谓,因为在屏幕外看不到 Shader.TileMode.MIRROR); Matrix matrix = new Matrix(); matrix.setTranslate(-mDisW, -mDisH); mBitmapShader.setLocalMatrix(matrix); }