2013-12-17 20 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