开发者

WPF - clone contents of container as geometry

开发者 https://www.devze.com 2023-03-14 10:46 出处:网络
Ok ive had a lot of bad luck using a visualbrush to try to print out pages from subsections of a large canvas. Works in general, but tends to rasterize some parts and creates bad output. (I\'ve asked

Ok ive had a lot of bad luck using a visualbrush to try to print out pages from subsections of a large canvas. Works in general, but tends to rasterize some parts and creates bad output. (I've asked questions about this before).

So now I'm creating a bunch of copies of the canvas with all the same contents, and pinching down to invidual portions to print as a single page. This works, but obviously is slow and will only get slower with more pages.

So what might work well is, is there some way to do something similar toa visual brush, but to instead have it copy th开发者_开发知识库e contents from its "view" as a new geometry object of some kind? The contents of my canvas are a combination of lines, images, etc, so what would be nice is to be able to define the view of a brush and tell it to make an intersection copy of all the vector and raster objects visible into a new container of some kind.

This would allow me to use a single canvas, and take "snapshots" of the contents at different places to be used for printing the individual pages.


You could use RenderTargetBitmap to get a bitmap copy of the Canvas, and then crop the portion you wanted. If you specifically want a vector copy you'd need to write the canvas out to XPS.

Edit: If you want a vector copy, have you tried using XamlWriter.Save, edit the Xaml, and then XamlReader.Load?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号