首页 > 代码库 > Android小应用-----画画板
Android小应用-----画画板
public class MainActivity extends Activity { private ImageView iv; float startX = 0; float startY = 0; //获得一个可以被bitmap Bitmap bitmap = Bitmap.createBitmap(400, 400,Bitmap.Config.ARGB_8888); //创建画布 Canvas canvas = new Canvas(bitmap); //创建画笔 Paint paint = new Paint(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); iv = (ImageView) this.findViewById(R.id.iv); paint.setColor(Color.BLACK); paint.setStrokeWidth(1);//设置像素 iv.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: startX = event.getX(); startY = event.getY(); break; case MotionEvent.ACTION_MOVE: float newX = event.getX(); float newY = event.getY(); canvas.drawLine(startX, startY, newX, newY, paint); iv.setImageBitmap(bitmap); break; case MotionEvent.ACTION_UP: break; default: break; } return true; } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。