本文介绍了StreamGeometry结合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有复杂的 StreamGeometry 和我想的的它。不幸的是,它看起来像 StreamGeometry 不支持结合起来。



下面是一个考验。



XAML中:

 <路径X:NAME =路径行程=红/> 



代码:

  VAR夹=新RectangleGeometry(新矩形(50,50,10,10)); 
变种矩形=新RectangleGeometry(新的Rect(0,0,100,100));
变种流=新StreamGeometry();
使用(VAR几何= stream.Open())
{
geometry.BeginFigure(新点(0,0),假的​​,真正的);
geometry.LineTo(新点(0,100),真,假);
geometry.LineTo(新点(100,100),真,假);
geometry.LineTo(新点(100,0),真,假);
}

//path.Data = RECT;
//path.Data =流;
//path.Data =夹;
//path.Data = Geometry.Combine(RECT,夹子,GeometryCombineMode.Intersect,NULL);
//path.Data = Geometry.Combine(流,夹子,GeometryCombineMode.Intersect,NULL);



取消注释第一行(显示 RECT )或第二线(对)产生相同的视觉效果:





取消注释第三行(显示片段)或第四线(对片段的交集 RECT )会产生:





虽然取消注释最后一行(对片段和路口几何)产生空白屏幕。



我的问题是:如何结合(剪辑)StreamGeometry



我知道有 UIElement.Clip ,但是:

  //黑屏
路径。数据=流;
path.Clip =夹;

//黑屏以及
path.Data =流;
path.Clip =夹;


解决方案

解决方法很简单:不使用StreamGeometry



为例子,这将工作(使用的PathGeometry 代替):

  VAR夹=新RectangleGeometry(新矩形(50,50,10,10)); 
变种几何=新的PathGeometry(新[] {新的PathFigure(新点(0,0),新的[] {
新线段(新点(0,100),真),
新线段(新点(100,100),真),
新线段(新点(100,0),真),
},真)});
path.Data = Geometry.Combine(剪辑,几何,GeometryCombineMode.Intersect,NULL);



结果:





很重要!



看起来 UIElement.Clip 渲染还是看不见的地方(mayhap仅 StreamGeometry )!不要使用它!剪辑的几何形状的之前分配它。


I have complex StreamGeometry and I want to clip it. Unfortunately, it looks like StreamGeometry doesn't supports combine.

Here is a test.

Xaml:

<Path x:Name="path" Stroke="Red"/>

Code:

var clip = new RectangleGeometry(new Rect(50, 50, 10, 10));
var rect = new RectangleGeometry(new Rect(0, 0, 100, 100));
var stream = new StreamGeometry();
using (var geometry = stream.Open())
{
    geometry.BeginFigure(new Point(0, 0), false, true);
    geometry.LineTo(new Point(0, 100), true, false);
    geometry.LineTo(new Point(100, 100), true, false);
    geometry.LineTo(new Point(100, 0), true, false);
}

//path.Data = rect;
//path.Data = stream;
//path.Data = clip;
//path.Data = Geometry.Combine(rect, clip, GeometryCombineMode.Intersect, null);
//path.Data = Geometry.Combine(stream, clip, GeometryCombineMode.Intersect, null);

Uncommenting first line (to show rect) or second line (to show stream) produces same visual result:

Uncommenting third line (to show clip) or fourth line (to show intersection of clip and rect) will produce:

While uncommenting last line (to show intersection of clip and geometry) produce blank screen.

My question is: how to combine (clip) StreamGeometry?

I know there is UIElement.Clip, but:

// blank screen
path.Data = stream;
path.Clip = clip;

// blank screen as well
path.Data = stream;
path.Clip = clip;
解决方案

Solution is simple: do not use StreamGeometry.

To example, this will work (using PathGeometry instead):

var clip = new RectangleGeometry(new Rect(50, 50, 10, 10));
var geometry = new PathGeometry(new[] { new PathFigure(new Point(0, 0), new[] {
    new LineSegment(new Point(0, 100), true),
    new LineSegment(new Point(100, 100), true),
    new LineSegment(new Point(100, 0), true),
}, true) });
path.Data = Geometry.Combine(clip, geometry, GeometryCombineMode.Intersect, null);

Result:

Very important!

It looks like UIElement.Clip still render invisible parts (mayhap only with StreamGeometry) ! Never use it! Clip geometry before assigning it.

这篇关于StreamGeometry结合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 01:15