2011-09-05 50 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