我正在尝试使用矢量可绘制对象来绘制到画布上。一切都很好,直到我将画布对象旋转90度或270度。当我越接近90度或270度时,在画布中显示的可绘制对象就会变得更加模糊。最终在90度或270度时,画布上的矢量可绘制对象完全消失了。是否有某种修复或解决方法?或者我应该使用其他库来使用SVG绘制到画布上?谢谢!
以下是代码:
这是项目链接:https://github.com/danskiess/VectorTest
以下是代码:
public class CanvasView extends View {
private static final String TAG = "CanvasView";
private VectorDrawableCompat vectorDrawableCompat;
private int angle;
public CanvasView(Context context) {
super(context);
init();
}
public CanvasView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public CanvasView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init(){
vectorDrawableCompat = VectorDrawableCompat.create(getResources(),
R.drawable.ic_android_black_24dp, null);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
vectorDrawableCompat.setBounds((getWidth()/2) - 50, (getHeight()/2) - 50, (getWidth()/2) + 50, (getHeight()/2) + 50);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.save();
canvas.rotate(angle, getWidth()/2, getHeight()/2);
vectorDrawableCompat.draw(canvas);
canvas.restore();
}
public void setAngle(int angle){
Log.i(TAG, "setAngle: " + angle);
this.angle = angle;
invalidate();
}
}
这是项目链接:https://github.com/danskiess/VectorTest