0
我在相對佈局中添加了自定義視圖,並且想要包含曲線文本的相對佈局的位圖,並且希望在imageview中存儲該位圖。如何將包含曲線文本的自定義視圖轉換爲位圖?
' RelativeLayout relativeLayout;
private ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
relativeLayout= (RelativeLayout) findViewById(R.id.rel);
imageView= (ImageView) findViewById(R.id.img1);
Circle circle=new Circle(MainActivity.this);
relativeLayout.addView(circle);
}
public class Circle extends View {
Paint paint = new Paint();
Path path = new Path();
private static final String s = "Hello world example";
public Circle(Context context) {
super(context);
paint.setColor(Color.BLACK);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(2);
paint.setAntiAlias(true);
paint.setTextSize(30);
}
public void onDraw(Canvas c) {
c.rotate(180, getWidth()/2, getHeight()/2);
path.addCircle(getWidth()/2, getHeight()/2, 90, Path.Direction.CW);
c.drawTextOnPath(s, path, 0, 10, paint);
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
}`'