dotnet / dotnet/wpf

PushOpacityMask bad behavior

Open
#7,703 0 comments 0 reactions 0 assignees View on GitHub
Investigate
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

### Description

I am try to make a Simth chat process, which using WPF: `public class test1 : Control {`
![NNBQUWFQ_3}IMCGS0$PC02J](https://user-images.githubusercontent.com/25917796/230999798-5fb86efa-e1e1-4973-9046-7962322bf05a.jpg)
I have to draw all arcs in the circle. So I need a mask
![image](https://user-images.githubusercontent.com/25917796/231000194-4ba4a8cc-b10e-4f86-aaf5-f7fcd59bb1b8.png)
When I draw the mask,
```c#

var mask_dg = new DrawingGroup();
mask_dg.Children.Add(new GeometryDrawing(Brushes.Black, base_pen, new EllipseGeometry(new Point(0, 0), 1, 1)));
mask_dg.Children.Add(new GeometryDrawing(Brushes.Transparent, base_pen, new EllipseGeometry(new Point(0, 0), 1000, 1000)));
drawingContext.DrawDrawing(mask_dg);
//drawingContext.PushOpacityMask(new DrawingBrush(mask_dg));
```
It work well, the black circle is masked.
than use PushOpacityMask():
```c#
drawingContext.PushOpacityMask(new DrawingBrush(mask_dg));
```
Something little here.:
![image](https://user-images.githubusercontent.com/25917796/231000688-97230809-4bc1-458c-b1d1-f0690175cf49.png)
Is the PushOpacityMask do not using the transform? let's try:
```c#
var mask_dg = new DrawingGroup();
mask_dg.Children.Add(new GeometryDrawing(Brushes.Black, base_pen, new EllipseGeometry(new Point(0, 0), 100, 100)));//change to 100 from 1
mask_dg.Children.Add(new GeometryDrawing(Brushes.Transparent, base_pen, new EllipseGeometry(new Point(0, 0), 1000, 1000)));
//drawingContext.DrawDrawing(mask_dg);
drawingContext.PushOpacityMask(new DrawingBrush(mask_dg));
foreach (var r in er_circle_r_table) {
drawingContext.DrawGeometry(Brushes.Transparent, R_pen, new EllipseGeometry(new Point(r / (1 + r), 0), 1 / (1 + r), 1 / (1 + r)));
drawingContext.DrawGeometry(Brushes.Transparent, G_pen, new EllipseGeometry(new Point(-r / (1 + r), 0), 1 / (1 + r), 1 / (1 + r)));
}
```
![image](https://user-images.githubusercontent.com/25917796/231001242-dee75d10-7967-4e92-9c4c-a90c8487ebf5.png)
WHY????????
![image](https://user-images.githubusercontent.com/25917796/231001407-e83cef6a-3cab-4747-a513-d4f67da878a4.png)

Mask should big than all draws.
```c#
mask_dg.Children.Add(new GeometryDrawing(Brushes.Transparent, base_pen, new EllipseGeometry(new Point(0, 0), 10000, 10000)));
```
If any draw out of mask, mask disabled.
![image](https://user-images.githubusercontent.com/25917796/231002760-814b0d28-5315-4d6d-87b1-7f0648c85ddb.png)

### Reproduction Steps

Chould you check my publish:
https://github.com/lee8871/SimthChat

### Expected behavior

May fix mask, may mask using same transform in DrawingContext.

### Actual behavior

![image](https://user-images.githubusercontent.com/25917796/231001407-e83cef6a-3cab-4747-a513-d4f67da878a4.png)

### Regression?

_No response_

### Known Workarounds

_No response_

### Impact

_No response_

### Configuration

Debug
AnyCPU
v4.8

### Other information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.