【问题标题】:Silverlight ImageTools.IO.Jpeg.JpegDecoder Bad QualitySilverlight ImageTools.IO.Jpeg.JpegDecoder 质量不佳
【发布时间】:2011-10-11 08:14:22
【问题描述】:

我正在使用ImageTools for Silverlight 加载 JPG 图片,但解码后的图片质量很差(没有抗锯齿,请参见红色方块中的第二张图片)。

这是我的代码:

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
}

源图片

不好的结果

观察

如果我将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();
        }
    }
}
}

结果

【问题讨论】:

标签: c# silverlight image-processing jpeg


【解决方案1】:

嗯...我认为如果您将问题发布到ImageTool codeplex forum 会是一个好主意,这个作者曾经回答得很快。

你检查过他网站上的样本吗?

通常我对这个库没有任何问题。

干杯 布劳略

【讨论】:

  • 覆盖文本“ImageTool codeplex forum”并带有指向该论坛的链接将提高此答案的质量。
  • 我已经在 codeplex imagetools.codeplex.com/discussions/271019 上发布了这个问题,但没有答案!!
【解决方案2】:

ImageTools 不支持抗锯齿,所以我从 Subversion 获得了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

谢谢大家!!

【讨论】:

    猜你喜欢
    • 2011-12-17
    • 2020-02-14
    • 2021-05-11
    • 2013-02-13
    • 1970-01-01
    • 1970-01-01
    • 2020-05-04
    • 1970-01-01
    • 2011-02-26
    相关资源
    最近更新 更多