路径超出画布界限

时间:2018-10-30 10:07:59

标签: java android canvas path

我正在尝试为视图的背景绘制轮廓...我几乎做到了,但是遇到了一个奇怪的错误...路径正在绘制画布的侧面...为什么会这样? Screenshot

代码:

final float[] rd = new float[8];
rd[0] = (float)_tlrdx;
rd[1] = (float)_tlrdy;
rd[2] = (float)_trrdx;
rd[3] = (float)_trrdy;
rd[4] = (float)_brrdx;
rd[5] = (float)_brrdy;
rd[6] = (float)_blrdx;
rd[7] = (float)_blrdy;
int[] colors = new int[_clr.size()-1];
for(int i = 0; i < _clr.size()-1; i++) {
colors[i] = Color.parseColor(_clr.get(i+1));
}
final android.graphics.drawable.GradientDrawable _btn_bg= new android.graphics.drawable.GradientDrawable(android.graphics.drawable.GradientDrawable.Orientation.TOP_BOTTOM, colors);  _btn_bg.setCornerRadii(rd); _view.setBackgroundDrawable(_btn_bg);
if(_outline) {
new Handler().postDelayed(new Runnable() {
@Override public void run() {
Bitmap scaledBitmap = Bitmap.createBitmap(_view.getWidth(), _view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(scaledBitmap);
canvas.setBitmap(scaledBitmap);
_btn_bg.draw(canvas);
Paint paint = new Paint();
paint.setColor(Color.parseColor(_clr.get(0)));
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(1000);
Rect rect = new Rect();
_view.getGlobalVisibleRect(rect);
Path path = new Path();
path.addRoundRect(new RectF(rect), rd, Path.Direction.CW);
path.close();
canvas.drawPath(path, paint);
canvas.drawBitmap(scaledBitmap,0,0,null);
android.graphics.drawable.BitmapDrawable background = new android.graphics.drawable.BitmapDrawable(scaledBitmap);
_view.setBackground(background);
}
}, 100);
}

0 个答案:

没有答案