Erasing the content from canvas where mouse is being dragged

痞子三分冷 提交于 2019-12-13 06:20:49

问题


I am developing a paint like application in metro style. I want to apply a eraser functionality. So how can I make such a tool for erasing the content from canvas like we do in MS paint ?

I don't want to clear whole canvas, wherever I click or drag the pointer, the path traveled by the pointer should be erased.


回答1:


The important thing to remember is that you're not "erasing." You're painting with small while pixels over the area that the mouse has traveled. There's 100 different ways to do this, but there isn't anything built-in to make this easy.

You're likely going to need to detect every pixel (or whatever unit of measure you choose) that the mouse (or finger) touches, and place a white Rectangle control over whatever else has already been drawn to the page.

This is mostly a game of managing a large collection of Rectangle objects, and changing their colors at the appropriate time. If you are trying to erase part of a larger Rectangle, you should rethink your approach.



来源:https://stackoverflow.com/questions/11227031/erasing-the-content-from-canvas-where-mouse-is-being-dragged

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!