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

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

问题描述

我使用 Viewport3D ModelVisual3D 创建一个带图像的简单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.BitmapScalingMode SnapsToDevicePixels 但似乎没有解决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="images\card.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天全站免登陆