如何在 WPF 3d 中制作非模糊图像 [英] How to make non-blurry image in WPF 3d

查看:23
本文介绍了如何在 WPF 3d 中制作非模糊图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Viewport3DModelVisual3D 用图像创建了一个简单的 ImageBrush(我用 JPG、PNG 尝试过),但它显示图像模糊,但原始图像图像非常清晰.

I used Viewport3D and ModelVisual3D to create a simple ImageBrush with an image (I tried it with JPG, PNG), but it shows the image blurry, but the original image is very sharp and clear.

我不知道如何以 3D 的原始质量制作它...

I don't know how to make it with the original quality in 3D...

我还尝试了一些 2D 解决方案,例如 RenderOptions.BitmapScalingModeSnapsToDevicePixels,但似乎无法解决 3D 情况下的问题.

I also tried some 2D solutions like RenderOptions.BitmapScalingMode and SnapsToDevicePixels but seem not fix the problem in the 3D case.

有没有人遇到过这个问题或者知道解决方法?

Has anyone encountered this problem or know the solution?

以下是示例代码:

<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    
Title="Window6" Height="600" Width="600">

<Window.Resources>
    <MeshGeometry3D x:Key="Card1" Positions="-0.67,1,0 -0.67,-1,0 0.67,-1,0 0.67,1,0"
        TextureCoordinates="0,0 0,1 1,1 1,0" TriangleIndices="0 1 2 0 2 3" />
</Window.Resources>
<DockPanel Height="600" Width="600">
    <Viewport3D Width="415.67" x:Name="viewport" Margin="0,23.363,0,64.363" DockPanel.Dock="Left">
        <Viewport3D.Camera>
            <PerspectiveCamera x:Name="perCamera" x:Uid="perCamera" FieldOfView="60" Position="0,0,5" />
        </Viewport3D.Camera>
        <ModelVisual3D>
            <ModelVisual3D.Content>
            <Model3DGroup >
                <GeometryModel3D Geometry="{StaticResource Card1}">
                    <GeometryModel3D.Material>
                        <DiffuseMaterial>
                            <DiffuseMaterial.Brush>
                                <ImageBrush ImageSource="imagescard.png"/>
                            </DiffuseMaterial.Brush>
                        </DiffuseMaterial>
                    </GeometryModel3D.Material>
                </GeometryModel3D>
                </Model3DGroup>
            </ModelVisual3D.Content>
        </ModelVisual3D>
        <!-- light -->
        <ModelVisual3D>
            <ModelVisual3D.Content>
                <DirectionalLight Color="#FFFFFFFF" Direction="0,0,-1"/>
            </ModelVisual3D.Content>
        </ModelVisual3D>

    </Viewport3D>
</DockPanel>

推荐答案

大多数图形硬件要求纹理的大小为 2 的幂(例如 512x512 像素).猜测,WPF 首先将图片的大小调整"到 2 的幂,然后将结果缩放到您需要的任何大小.从 2 的幂缩放到所需的目标大小通常是通过一种强调速度而不是质量的算法来完成的(除非你做一些其他事情来指定,我没有看到上面的内容).

Most graphics hardware requires that the size of a texture be a power of 2 (e.g. 512x512 pixels). At a guess, WPF is first "adjusting" your picture's size to a power of 2, then scaling that result to whatever size you need. Scaling from the power of 2 to the required target size is typically done with an algorithm that emphasizes speed over quality (unless you do something to specify otherwise, which I don't see an what's above).

为了验证这个假设,我会创建一个尺寸为 2 的幂的绘图,然后我会以完全原始的分辨率显示它.如果这是问题的根源,则应尽量减少(甚至消除)问题.

To test that hypothesis, I'd create a drawing with its dimensions both powers of two, then I'd display it at exactly the original resolution. If that is the source of the problem, this should minimize (or even eliminate) the problem.

这篇关于如何在 WPF 3d 中制作非模糊图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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