我有一部分应用程序,我从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模拟器中,它工作正常。