WPF巨大视觉效果的不精确渲染-有解决方案吗? [英] Unprecise rendering of huge WPF visuals - any solutions?

查看:116
本文介绍了WPF巨大视觉效果的不精确渲染-有解决方案吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WPF中渲染巨大的视觉效果时,视觉效果会随着坐标的增加而失真,并且会更加失真.我认为这与渲染管道中使用的浮点数据类型有关,但我不确定.无论哪种方式,我都在寻找解决该问题的实用方法.

When rendering huge visuals in WPF, the visual gets distorted and more distorted with increasing coordinates. I assume that it has something to do with the floating point data types used in the render pipeline, but I'm not completely sure. Either way, I'm searching for a practical solution to solve the problem.

为了演示我在说什么,我创建了一个示例应用程序,该应用程序仅包含嵌入绘制正弦曲线的ScrollViewer中的自定义控件.

To demonstrate what I'm talking about, I created a sample application which just contains a custom control embedded in a ScrollViewer that draws a sine curve.

在这里您可以看到,对于< = 2 ^ 24(在这种情况下为水平坐标值)的双精度值,该图是正确的,但是从那一点开始,它就失真了.

You can see here that the drawing is alright for double values <= 2^24 (in this case the horizontal coordinate value), but from that point on it gets distorted.

畸变在2 ^ 25时变得更糟,因此畸变继续增加,直到它仅画出一些垂直线为止.

The distortion gets worse at 2^25 and so the distortion continues to increase with every additional bit until it just draws some vertical lines.

出于性能原因,我只是在绘制图形的可见部分,但出于布局原因,我无法虚拟化"使该问题过时的控件.我唯一能想到的解决方案是将图形的可见部分绘制到位图上,然后在适当的位置渲染位图-但是我又遇到了较大值的精度问题,因为我无法准确地放置位图在我需要的位置.

For performance reasons I'm just drawing the visible part of the graph, but for layouting reasons I cannot "virtualize" the control which would make this problem obsolete. The only solution I could come up with is to draw the visible part of the graph to a bitmap, and then render the bitmap at the appropriate point - but there I have again the precision problem with big values, as I cannot accurately place the bitmap at the position where I need it.

有人知道如何解决这个问题吗?

Does anybody have an idea how to solve this?

推荐答案

(更新:哦,没有看到这篇文章的年龄...我想我在堆栈溢出中单击了错误的筛选器按钮...)

(update: oh didnt see how old this post was... i guess i clicked the wrong filter button in stack overflow...)

相对精度在这里是相关的.因此,仅说看起来2 ^ 24很好而2 ^ 25不好"是不够的信息.您说这是一种罪过,因此我想y轴的最大值和最小值在这些图片之间永远不变.因此,y轴无关紧要.而且,x步长保持不变,我猜呢?但是您没有告诉我们选择的正弦周期长度或x步长.这是相关的.当您使用更高的x值时,x步长的相对精度会变差,因为x步长相对于x值本身而言变得太小了.

The relative precision is relevant here. So just saying "look 2^24 is fine and 2^25 is not" is not enough information. You said it is a sin, thus I guess y-axis max and min never changes between those pictures. So y-axis doesnt matter. Furthermore the x-step size stays the same, i guess? But you did not tell us the sin period length or the x-step size, you chose. That is relevant here. The relative precision of the x-size steps becomes worse when you go to higher x-values, because the x-step-size becomes too small relativly to the x-value itself.

c#浮点类型的精度: https://docs.microsoft.com/de-de/dotnet/csharp/language-reference/builtin-types/floating-point-numeric-types

precision of c# floating point types: https://docs.microsoft.com/de-de/dotnet/csharp/language-reference/builtin-types/floating-point-numeric-types

示例:
x步长=1.
x = 1(没问题)
x = 1000(没问题)
x => 2 ^ 23(32位开始出现问题,步长= 1; 64位没有问题)
x => 2 ^ 52(64位开始出现步长= 1的问题)

example:
x-step size = 1.
x = 1 (no problem)
x = 1000 (no problem)
x = >2^23 (32 bit starts to get problems with step size = 1; 64 bit no problems yet)
x = >2^52 (64 bit starts to get problems with step size = 1)

这篇关于WPF巨大视觉效果的不精确渲染-有解决方案吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆