2011-09-05 51 views
1

我使用ImageTools for Silverlight来加载JPG图像,但解码图像质量是坏的(没有抗锯齿,请参见红色的第二个图像)。Silverlight ImageTools.IO.Jpeg.JpegDecoder质量差

这里是我的代码:

OpenFileDialog dlg = new OpenFileDialog(); 

if (dlg.ShowDialog() == true) 
{ 
    var stream = dlg.File.OpenRead(); 
    var newImg = new ExtendedImage(); // ExtendedImage is a ImageTools Api class 
    var d= new ImageTools.IO.Jpeg.JpegDecoder(); 
    d.Decode(newImg, stream); 
    image1.Source = newImg.ToBitmap(); //image1 is a System.Windows.Controls.Image 
} 

源图像

this is the source image

坏的结果

this is the bad result

观察

如果我将image1.source直接设置为来自原始图像的URL,图像就会正确呈现!

这是ImageTools API中的错误吗?

The problem is posted on Codeplex,但它没有任何答案。

如果我重写我的代码,我会得到相同的结果。

XAML

<UserControl x:Class="JPGDecoder.MainPage" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d" 
d:DesignHeight="300" d:DesignWidth="400"> 

<Grid x:Name="LayoutRoot" Background="White"> 
    <Image Height="120" HorizontalAlignment="Left" Margin="46,75,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="160" Source="/JPGDecoder;component/Images/org.jpg" /> 
    <Image Height="120" HorizontalAlignment="Left" Margin="212,75,0,0" Name="image2" Stretch="Fill" VerticalAlignment="Top" Width="160" /> 
    <Button Content="Decode JPG from File Stream" Height="23" HorizontalAlignment="Left" Margin="44,25,0,0" Name="button1" VerticalAlignment="Top" Width="192" Click="button1_Click" /> 
</Grid> 

C#

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Net; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Shapes; 
using ImageTools; 

namespace JPGDecoder 
{ 
public partial class MainPage : UserControl 
{ 
    public MainPage() 
    { 
     InitializeComponent(); 
    } 

    private void button1_Click(object sender, RoutedEventArgs e) 
    { 
     var dlg = new OpenFileDialog(); 

     if (dlg.ShowDialog()==true) 
     { 
      var stream = dlg.File.OpenRead(); 
      var newImg = new ExtendedImage(); 
      var d = new ImageTools.IO.Jpeg.JpegDecoder(); 
      d.Decode(newImg, stream); 
      image2.Source = newImg.ToBitmap(); 
     } 
    } 
} 
} 

结果

enter image description here

+1

[ImageTools.IO.Jpeg.JpegDecoder Bad Quality](http://stackoverflow.com/questions/7230834/imagetools-io-jpeg-jpegdecoder-bad-quality) – AnthonyWJones

+1

请仅调整您的内容原来的问题,而不是再次要求同一个问题。 – AnthonyWJones

+0

我投票做删除第一篇文章,对不起! – JoeLoco

回答

0

ImageTools不支持antialising,所以我从颠覆了FJCore,并运行示例应用程序。

  1. 首先测试结果相同,质量差。
  2. 综观源代码,我发现这个代码块:

    // Resize 
    DecodedJpeg jpegOut = new DecodedJpeg(
        new ImageResizer(jpegIn.Image).Resize(320, ResamplingFilters.NearestNeighbor), 
        jpegIn.MetaHeaders); // Retain EXIF details 
    

    ,并将其改变为这样:

    //Resize 
    DecodedJpeg jpegOut = new DecodedJpeg(
        new ImageResizer(jpegIn.Image).Resize(320, ResamplingFilters.LowpassAntiAlias), 
        jpegIn.MetaHeaders); // Retain EXIF details 
    

这是解决方案:ResamplingFilters。LowpassAntiAlias

谢谢大家!

0

嗯...我想,如果你婆那将是一个好主意对ImageTool codeplex forum提出问题,这位作者曾经很快回答。

您是否检查过他的网站上的样本?

通常我没有这个库的问题。

干杯 布劳

+1

覆盖文本“ImageTool codeplex论坛”与指向论坛的链接将提高此答案的质量。 – AnthonyWJones

+0

我已经在codeplex上发布了这个问题,http://imagetools.codeplex.com/discussions/271019,但没有答案! – JoeLoco