2014-05-06 54 views
0

我有我的應用程序的一部分,我從CameraCaptureTask保存照片。手機媒體庫中的照片很好。我想將照片也保存到IsolatedStorage。這是我保存方法:本地保存的位圖圖像在物理設備上顯示奇怪

private void SavePhoto(Stream image, string filename) 
{ 
    using (IsolatedStorageFile storageFolder = IsolatedStorageFile.GetUserStoreForApplication()) 
    { 
     using (IsolatedStorageFileStream fileStream = storageFolder.CreateFile(filename)) 
     { 
      var bitmap = new BitmapImage(); 
      bitmap.SetSource(image); 

      var wb = new WriteableBitmap(bitmap); 
      wb.SaveJpeg(fileStream, wb.PixelHeight, wb.PixelWidth, 0, 100); 
      fileStream.Close(); 
     } 
    } 
} 

這是方法在另一個頁面顯示照片的一部分:

{... 
    using (IsolatedStorageFile storageFolder = IsolatedStorageFile.GetUserStoreForApplication()) 
    { 
     using (IsolatedStorageFileStream fileStream = storageFolder.OpenFile(_url, FileMode.Open, FileAccess.Read)) 
     { 
      BitmapImage image = new BitmapImage(); 
       image.SetSource(fileStream); 
     } 
     this.fullImage.Source = image; 
    } 
    } 

XAML代碼:

<ViewportControl x:Name="viewport" 
    ManipulationStarted="OnManipulationStarted" 
    ManipulationDelta="OnManipulationDelta" 
    ManipulationCompleted="OnManipulationCompleted" 
    ViewportChanged="viewport_ViewportChanged"> 
    <Canvas x:Name="canvas"> 
     <Image x:Name="fullImage" HorizontalAlignment="Center" 
       RenderTransformOrigin="0,0" 
       VerticalAlignment="Center" 
       CacheMode="BitmapCache" 
       Stretch="UniformToFill" > 
       <Image.RenderTransform> 
        <ScaleTransform x:Name="xform"/> 
       </Image.RenderTransform> 
     </Image> 
    </Canvas> 
</ViewportControl> 

圖像加載和顯示,但這很奇怪,它有一種拉伸,另一邊變窄。對不起,自WP 8.1升級以來,我無法進行截圖,我不知道爲什麼。在Windows Phone Emulator中,它工作正常。

回答

1

我正面臨類似的情況。我使用PhotoCaptureDevice捕獲的圖像,我試圖在單獨的頁面(它也實現了縮放平移功能)中顯示它,圖像正在顯示裁剪。如果我從Image中刪除CacheMode = "BitmapCache"屬性,則圖像不再被裁剪。但它使圖像的縮放變得非常緊張。

在Windows Phone環境中似乎存在大小限制(2000 x 2000)的圖像大小。見this

看看FilterExplorerWPproject中的PhotoPage.xamlPhotoPage.xaml.cs文件。它可能會幫助你。

相關問題