petrppe
petrppe

Reputation: 155

Local saved bitmap image displayed weird on physical device

I have a part of my application where I am saving photo from CameraCaptureTask. Photos from here in phone's Media Library are fine. I want to save photos also to IsolatedStorage. This is my method for saving:

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();
       }
   }
}

And this is the part of method displaying photo in another page:

{...
     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 code:

<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>

Image is loaded and displayed but it's weird, it's kind of stretched on one side and narrowed on second side. I'm sorry, I can't take a screenshot since WP 8.1 upgrade, I don't know why. In Windows Phone Emulator it's working fine though.

Upvotes: 0

Views: 149

Answers (1)

Ratish
Ratish

Reputation: 201

I am facing a similar scenario. The image, which I am capturing using PhotoCaptureDevice, I am trying to display it in a separate page (which also implements the zoom pan feature), the image is being shown cropped. If I remove the CacheMode = "BitmapCache" attribute from Image, then the image is no longer cropped. However it makes the zoom & pan of the image very jittery.

It seems that there is a size limit (2000 x 2000) of image size in the Windows Phone environment. See this.

Do have a look at the PhotoPage.xaml and PhotoPage.xaml.cs files in the FilterExplorerWP project . It might help you.

Upvotes: 1

Related Questions