2013-12-17 18 views
0

我正在尝试将本地路径中的图像加载到Silverlight图像控件。这是一个浏览器外的应用程序。当我使用流加载图像时,它总是翻转过来。从文件流中读取图像时翻转-90

任何想法为什么?这仅适用于大图像。

FileName这里给出了本地文件系统的完整路径,如C:\imageFullPath\image.jpg

请帮忙。以下是代码。

------在模型侧------------------------

public BitmapImage DisplayImage 
{ 
    get 
    { 
     if (!string.IsNullOrWhiteSpace(FileName)) 
     { 
      var b = new BitmapImage(); 
      b.SetSource(System.IO.File.OpenRead(FileName));      
      return b; 
     } 
     return null; 
    } 
} 

------在Silverlight浏览侧------------------------

<Image Source="{Binding DisplayImage, Mode=TwoWay}" Width="450" Height="250" Margin="0,0,0,0"/> 

我看到什么样的调试

enter image description here

回答

0

BMP时是normally stored "upside-down"与从底部到顶部相反的顺序像素,但可以在文件头中使用负高度来指示图像从顶部到底部存储,因此也许您有这样的图像。

这是发生在所有的图像,还是只有一个?

你可以尝试改变图像加载的方式,用在构造一个Uri而不是调用SetSource()Stream,因为它可能占头和不同的读取文件:

var b = new BitmapImage(new Uri(FileName));      
return b; 

或者,如果没有帮助,可以用apply a transform来翻转每张图片,但这并不能解决底层问题:

<Image Source="{Binding DisplayImage, Mode=TwoWay}" Width="450" Height="250" Margin="0,0,0,0"> 
    <Image.RenderTransform> 
     <ScaleTransform ScaleY="-1" /> 
    </Image.RenderTransform> 
</Image> 
+0

感谢您的回复。 发生这种情况只有大图像不仅仅是这一个,而是每个大图像。我已经尝试第一种方法var b = new BitmapImage(new Uri(FileName)); 但这只是返回空图像。 第二个对我来说不实际,因为我不得不在模型中决定所有这些,而不是在xaml中。任何其他想法? – AllSpark