标签:
private ImageView iv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); iv = (ImageView) findViewById(R.id.iv); final Bitmap bitmap = BitmapFactory.decodeFile("/storage/sdcard/blank_500_500.png"); //只能在副本图片上修改 final Bitmap copyBitmap = Bitmap.createBitmap(bitmap.getWidth(),bitmap.getHeight(),bitmap.getConfig()); final Canvas canvas = new Canvas(copyBitmap); final Paint paint = new Paint(); paint.setColor(Color.RED); //线的宽度 paint.setStrokeWidth(6); if (bitmap != null) { iv.setImageBitmap(copyBitmap); } iv.setOnTouchListener(new View.OnTouchListener() { int startX = 0; int startY = 0; int endX = 0; int endY = 0; @Override public boolean onTouch(View v, MotionEvent event) { int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: startX = (int) event.getX(); startY = (int) event.getY(); case MotionEvent.ACTION_UP: break; case MotionEvent.ACTION_MOVE: endX = (int) event.getX(); endY = (int) event.getY(); canvas.drawLine(startX,startY,endX,endY,paint); startX = endX; startY = endY; iv.setImageBitmap(copyBitmap); } return true;//true } }); }
SD卡权限
标签:
原文地址:http://www.cnblogs.com/linson0116/p/5691354.html