IT技术问答
联系我们
IT技术问答

Android小应用-----画画板

发布人:凯发K 发布时间:2019-01-26

public class MainAct亚美娱乐ivity 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;
	}

}

http://www.bkjia.com/Androidjc/771795.htmlwww.bkjia.comtruehttp://www.bkjia.com/Androidjc/771795.htmlTechArticlepublic class MainActivity extends Activity {private ImageView iv;float startX = 0;float startY = 0;//获得一个可以被bitmapBitmap bitmap = Bitmap.createBitmap(400, 400,Bitmap....

本文源自: 环亚娱乐

上一篇:[Unity3D]Unity3D游戏开发之使用UniSky呼风唤雨
下一篇:没有了