撕衣服

来源:互联网 发布:手机音乐频谱显示软件 编辑:程序博客网 时间:2022/01/24 06:25
public class MainActivity extends Activity {private Bitmap bmCopy;private ImageView iv;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Bitmap bmSrc = BitmapFactory.decodeResource(getResources(), R.drawable.awaiyi);bmCopy = Bitmap.createBitmap(bmSrc.getWidth(), bmSrc.getHeight(), bmSrc.getConfig());Paint paint = new Paint();Canvas canvas = new Canvas(bmCopy);canvas.drawBitmap(bmSrc, new Matrix(), paint);iv = (ImageView) findViewById(R.id.iv);iv.setOnTouchListener(new OnTouchListener() {@Overridepublic boolean onTouch(View v, MotionEvent event) {switch (event.getAction()) {case MotionEvent.ACTION_MOVE:int x = (int) event.getX();int y = (int) event.getY();for(int i = -5; i <= 5; i++){for(int j = -5; j <= 5; j++){//把用户划过的坐标置为透明色//改变指定的像素颜色if(Math.sqrt(i*i + j*j) <= 5){if(x + i < bmCopy.getWidth() && y + j < bmCopy.getHeight() && x + i >= 0 && y + j >= 0){bmCopy.setPixel(x + i, y + j, Color.TRANSPARENT);iv.setImageBitmap(bmCopy);}}}}break;}return true;}});}}

0 0
原创粉丝点击