How to make non-blurry image in WPF 3d
I used V开发者_JAVA技巧iewport3D
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.
I don't know how to make it with the original quality in 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?
below is sample code:
<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>
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).
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.
Use UseLayoutRounding="True"
property for the Image element.
精彩评论