How to implement an image backgound eraser?(Like PS) #8855
-
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 17 replies
-
You can utilize the Clip feature to achieve this function. In WPF, clipping can be accomplished by assigning a value to the Clip property. Additionally, you can push the clipping range in the DrawingContext for more granular control. Below is a screenshot of a WPF application that my team has developed. In this application, we used the calculated eraser path geometry in conjunction with assigning a value to the Clip property to achieve the erasing effect. |
Beta Was this translation helpful? Give feedback.
-
You could also just use |
Beta Was this translation helpful? Give feedback.
@BigHeadDev Continuously calculate the geometric shape constructed between the current mouse drop point and the previous one, then overlay it with the current Clip using the Geometry.Combine method in the GeometryCombineMode.Exclude mode. This will allow the clipping part to continuously subtract the current mouse trajectory. The mouse trajectory, as shown in the figure below, is a combination of two circles and a rectangle.
不断的计算当前鼠标落点和上个鼠标落点之间构建的几何形状,然后通过 Geometry.Combine 方式与当前 Clip 采用 GeometryCombineMode.Exclude 方式叠加,如果即可让裁剪部分源源不断减去当前鼠标的轨迹。鼠标轨迹如下图,就是两个圆形和矩形的拼接