在画布上添加了一些文本,如下所示,如何在画布上实现文本的拖动功能和缩放功能。这是我在画布上添加一些文字的代码
public class Test extends Activity {
ImageView drawingImageView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
drawingImageView = (ImageView) this.findViewById(R.id.DrawingImageView);
Bitmap bitmap = Bitmap.createBitmap((int) getWindowManager()
.getDefaultDisplay().getWidth(), (int) getWindowManager()
.getDefaultDisplay().getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawingImageView.setImageBitmap(bitmap);
// Custom Font Text
Paint paint = new Paint();
paint.setColor(Color.GREEN);
paint.setTextSize(40);
Typeface chops = Typeface.createFromAsset(this.getAssets(),
"WC_Speed_Bold_Bta.ttf");
paint.setTypeface(chops);
float text_x = 120;
float text_y = 120;
canvas.drawText("Hello", text_x, text_y, paint);
}
}
答案 0 :(得分:0)
缩放添加
canvas.scale(scalefactor, scalefactor);
这里scalefactor将是您想要缩放画布的比例值(如scalefactor = 1.5f)。