WPF的Image加载有metadata数据的图片出错

咋了啦 2011-12-13 11:38:45
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace wpfImageMetadata
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();

JpegBitmapDecoder decoder = new JpegBitmapDecoder(new Uri("pack://application:,,,/Images/4.jpg"),
BitmapCreateOptions.None, BitmapCacheOption.None);

BitmapMetadata metadata = (BitmapMetadata)decoder.Frames[0].Metadata;

BitmapImage bi = new BitmapImage();

// lock
bi.BeginInit();
bi.UriSource = new Uri("pack://application:,,,/Images/4.jpg");
bi.EndInit();

Image img = new Image();
img.Source = bi;
img.Height = 400;

mainCanvas.Children.Add(img);
}
}
}



<Window x:Class="wpfImageMetadata.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="547" Width="733">
<Canvas Background="AliceBlue" Name="mainCanvas">
</Canvas>
</Window>


这是使用的图片

当执行到 bi.EndInit();的时候,报错“Value does not fall within the expected range”

异常截图图片为


但是如果清除了照片的metadata数据,执行没有任何问题的。不知道大家遇到这个问题没有?很古怪的。
...全文
239 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
咋了啦 2011-12-20
  • 打赏
  • 举报
回复
这个问题有人帮忙深究下么,因为我们要处理的照片是客户提供,我说照片有问题,又不能说出到底是什么问题的。
咋了啦 2011-12-13
  • 打赏
  • 举报
回复
希望能够得到大家的帮助的,如果我把图片在ps中另存为一下,再次读取就又没有任何问题的
咋了啦 2011-12-13
  • 打赏
  • 举报
回复
如果像素有问题,那为什么windows自带的图片浏览器,以及PS可以打开啊
咋了啦 2011-12-13
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 bushiyundeyu 的回复:]

你好,经过我在本地的测试,你那张图片的像素格式有问题,不能被正确的解析。
你再Ps中经过转码之后才能被正确的识别。可以这张图片在某个传输的过程中丢失了一些信息或者代码。
[/Quote]


像素格式有么问题呢?可以看出来么?
Architecture Net 2011-12-13
  • 打赏
  • 举报
回复
只是图片的问题,和你的代码没有关系,你可以尝试使用其他的图片,然后用你的代码来加载应该不会再出错了。
Architecture Net 2011-12-13
  • 打赏
  • 举报
回复
你好,经过我在本地的测试,你那张图片的像素格式有问题,不能被正确的解析。
你再Ps中经过转码之后才能被正确的识别。可以这张图片在某个传输的过程中丢失了一些信息或者代码。

8,737

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧