Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] [XPS] Drawing a Visual is always being rasterized #4466

Open
wstaelens opened this issue Apr 30, 2021 · 4 comments
Open

[Question] [XPS] Drawing a Visual is always being rasterized #4466

wstaelens opened this issue Apr 30, 2021 · 4 comments

Comments

@wstaelens
Copy link
Contributor

XPS: When drawing a Visual on a DrawingContext of a FixedPage, the image is being rasterized and losing the Vector quality.

DrawingContextWrapper cntxt;
Visual visualToDraw;
// ...

var drawing = VisualTreeHelper.GetDrawing(visualToDraw); // <-- vector
System.Windows.Media.ImageSource image = new DrawingImage(drawing); 
cntxt.Canvas.DrawImage(image, drawingBounds.ToRect()); // <-- raster

How to draw a Visual on a DrawingContext as a vector without it being rasterized (XPS)?

(found something related but not really the same: https://stackoverflow.com/questions/6490576/wpf-image-vector-format-export-xps/ )

@miloush
Copy link
Contributor

miloush commented May 4, 2021

Do you have a simple repro? Does adding the visual directly to the FixedPage instead of rendering it on its DrawingContext work for you? (I tried with an ellipse but it looked vector in a DocumentViewer)

@wstaelens
Copy link
Contributor Author

I don't have a separate solution with a small repro but the code already posted above shows the problem.

  1. First you have to open an XPS document
  2. Get a FixedPage from the document
  3. Pass that FixedPage as a visual to the code below
  4. The code below takes the vector drawing via the VisualTreeHelper.GetDrawing. When we try to draw the Visual on a different DrawingContext of a different FixedPage it gets rasterized.
    When drawing the Visual on the same DrawingContext of the FixedPage it is Vector/good quality.
DrawingContextWrapper cntxt;
Visual visualToDraw;
// ...

var drawing = VisualTreeHelper.GetDrawing(visualToDraw); // <-- vector
System.Windows.Media.ImageSource image = new DrawingImage(drawing); 
cntxt.Canvas.DrawImage(image, drawingBounds.ToRect()); // <-- raster

@ryalanms ryalanms added this to the 7.0.0 milestone Sep 2, 2021
@wstaelens
Copy link
Contributor Author

any updates?

@wstaelens
Copy link
Contributor Author

🥱

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants