[WPF] Image의 Source가 Uri일 경우 특수한 문제점 해결
<Window x:Class="WpfApplication2.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Image x:Name="img1" Grid.Column="0"
Source="http://sp1.mm-a4.yimg.com/image/2954925478" />
<Image x:Name="img2" Grid.Column="1"
Source="http://chaoskcuf.com/attach/1/1387427076.jpg" />
</Grid>
</Window>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Image x:Name="img1" Grid.Column="0"
Source="http://sp1.mm-a4.yimg.com/image/2954925478" />
<Image x:Name="img2" Grid.Column="1"
Source="http://chaoskcuf.com/attach/1/1387427076.jpg" />
</Grid>
</Window>
위와 같은 코드는 보기에는 아무 문제가 없지만,
실행을 시켜보면 참 난감한 상황이 발생합니다.

http://sp1.mm-a4.yimg.com 이쪽 서버가 옛날 방식이고 무언가 비표준틱(?)한 구현을 해놓아서
그런지 아무래도 이미지가 보이질 않습니다.
http://sp1.mm-a4.yimg.com/image/2954925478 근데 이쪽 링크를 따라가서 웹브라우저에서
본다면 아무문제가 없이 잘 보입니다.
Procedure Code로 아래와 같이 구현을 하여도 역시 나오질 않습니다.
BitmapImage bitmap = new BitmapImage(new Uri("http://sp1.mm-a4.yimg.com/image/2954925478"));
img1.Source = bitmap;
가끔 Exception(ServerProtocolViolation)도 뿜어줄 때가 있습니다.
그럼 해결책은 있을까요?

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true" />
</settings>
</system.net>
</configuration>
<configuration>
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true" />
</settings>
</system.net>
</configuration>
위와 같이 useUnsafeHeaderParsing 값을 true 로 변경하시면 됩니다.
기본이 false이고 저 값이 false일 때는 아래와 관련된 http parsing 오류가 발생하면 Image 로드를 실패하게 됩니다.
In end-of-line code, use CRLF; using CR or LF alone is not allowed.
Headers names should not have spaces in them.
If multiple status lines exist, all additional status lines are treated as malformed header name/value pairs.
The status line must have a status description, in addition to a status code.
Header names cannot have non-ASCII chars in them. This validation is performed whether this property is set to true or false
"프로그래밍 / TIP& Study" 분류의 다른 글
| [퀴즈] SQLite collate 문제 (0) | 2010/07/16 |
| [TIP] XP, Vista에서 CD/DVD롬이 보이지 않을 경우 (1) | 2009/08/05 |
| [C#] WinForm 에서 Docking 순서 변경하기 (0) | 2009/07/29 |
| [WPF] InkCanvas 사용하기 (0) | 2009/06/29 |
| [C#] Control Library 만들 때 TIP (0) | 2009/06/26 |
| [C#] 자연스럽게 Pen으로 그리기 (0) | 2009/06/23 |
| [WPF] Canvas의 Width, Height Binding (0) | 2009/06/23 |
| [C#] DateTime으로 7일 후는 어떻게? (0) | 2009/06/23 |
프로그래밍/TIP& Study
2007/09/04 09:51

댓글을 달아 주세요