Android六边形图像
生活随笔
收集整理的這篇文章主要介紹了
Android六边形图像
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Android六邊形圖像
Glide.with(mContext).asBitmap().load(ranking.get(2).getGame_image().replace(":\\/", "/").toString()).into(new SimpleTarget<Bitmap>() {@Overridepublic void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {DefineView defineView=new DefineView();Bitmap nBM = scaleBitmap(resource, 1.5f);defineView.setBitmap(nBM);iv_racking.setBackground(defineView);} }); public class DefineView extends Drawable {Rect mRect = new Rect();Paint mPaint;Path mPath;BitmapShader mShader;Bitmap mBitmap;public DefineView() {this(null);}public DefineView(Bitmap bitmap) {init();/* int w=bitmap.getWidth();int h=bitmap.getHeight();float sx=(float)w;//要強制轉換,不轉換我的在這總是死掉。float sy=(float)h;Matrix matrix = new Matrix();matrix.postScale(sx, sy); // 長和寬放大縮小的比例Bitmap resizeBmp = Bitmap.createBitmap(bitmap, 0, 0, w,h, matrix, true); */setBitmap(bitmap);}public void setsView(Bitmap bitmap){init();setBitmap(bitmap);}private void init() {initPaint();initPath();}private void ensurePaint() {if (mPaint == null) {mPaint = new Paint();}}private void ensurePath() {if (mPath == null) {mPath = new Path();}}private void initPaint() {ensurePaint();mPaint.setAntiAlias(true);mPaint.setStyle(Paint.Style.FILL);mPaint.setStrokeWidth(3f);}public Bitmap getBitmap() {return mBitmap;}// 設置Bitmap的時候初始化shader,并設置給paintpublic void setBitmap(Bitmap bitmap) {this.mBitmap = bitmap;if (bitmap == null) {mShader = null;} else {mShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);mPaint.setShader(mShader);}}private int mWidth;private int mHeight;private int mLength;// 初始化好Path要走的路徑private void initPath() {ensurePath();float l = (float) (mRect.width() / 2);float h = (float) (Math.sqrt(3) * l);float top = (mRect.height() - h) / 2;mPath.reset();mPath.moveTo(l / 2, top);mPath.lineTo(0, h / 2 + top);mPath.lineTo(l / 2, h + top);mPath.lineTo((float) (l * 1.5), h + top);mPath.lineTo(2 * l, h / 2 + top);mPath.lineTo((float) (l * 1.5), top);mPath.lineTo(l / 2, top);mPath.close();}@Overridepublic void draw(Canvas canvas) {canvas.drawPath(mPath, mPaint);}@Overridepublic void setAlpha(int alpha) {if (mPaint != null) {mPaint.setAlpha(alpha);}}@Overridepublic void setColorFilter(ColorFilter colorFilter) {if (mPaint != null) {mPaint.setColorFilter(colorFilter);}}@SuppressLint("WrongConstant")@Overridepublic int getOpacity() {return 0;}@Overridepublic void setBounds(int left, int top, int right, int bottom) {super.setBounds(left, top, right, bottom);mRect.set(left, top, right, bottom);initPath();}@Overridepublic int getIntrinsicWidth() {if (mBitmap != null) {return mBitmap.getWidth();} else {return super.getIntrinsicWidth();}}@Overridepublic int getIntrinsicHeight() {if (mBitmap != null) {return mBitmap.getHeight();}return super.getIntrinsicHeight();} }總結
以上是生活随笔為你收集整理的Android六边形图像的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何自嘲自己对车是白痴
- 下一篇: Android切换到主线程