我有一个带有圆角方法的位图:
码:
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) { Bitmap output = Bitmap.createBitmap(bitmap.getWIDth(), bitmap.getHeight(), Config.ARGB_8888); BitmapDrawable TileMe = new BitmapDrawable(output); TileMe.setTileModeX(Shader.TileMode.REPEAT); TileMe.setTileModeY(Shader.TileMode.REPEAT); Canvas canvas = new Canvas(TileMe); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWIDth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); final float roundPx = pixels; paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setcolor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
这仅使图像具有圆角,并且角也不平滑,现在我如何使其与重复模式以及圆角一起平铺?
解决方法:
终于我解决了!
class CurvedAndTiled extends Drawable { private final float mCornerRadius; private final RectF mRect = new RectF(); private final BitmapShader mBitmapShader; private final Paint mTilePaint; CurvedAndTiled( Bitmap bitmap, float cornerRadius) { mCornerRadius = cornerRadius; mBitmapShader = new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); mTilePaint = new Paint(); mTilePaint.setAntiAlias(true); mTilePaint.setShader(mBitmapShader); } @OverrIDe protected voID onBoundsChange(Rect bounds) { super.onBoundsChange(bounds); mRect.set(0, 0, bounds.wIDth(), bounds.height()); } @OverrIDe public voID draw(Canvas canvas) { canvas.drawRoundRect(mRect, mCornerRadius, mCornerRadius, mTilePaint); } @OverrIDe public int getopacity() { return PixelFormat.TRANSLUCENT; } @OverrIDe public voID setAlpha(int Alpha) { mTilePaint.setAlpha(Alpha); } @OverrIDe public voID setcolorFilter(colorFilter cf) { mTilePaint.setcolorFilter(cf); } }
也将其应用于您的图像视图.
backgroundImage.setBackgroundDrawable(new CurvedAndTiled(((BitmapDrawable) drawable).getBitmap(), 45));
希望以后能对某人有所帮助.
快乐编码:)
总结以上是内存溢出为你收集整理的瓷砖模式重复和圆角的位图全部内容,希望文章能够帮你解决瓷砖模式重复和圆角的位图所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)