Ste*_*Pet 8 windows-phone-7 windows-phone windows-phone-8
这是我用于在XAML中绑定图像的代码
<Border toolkit:TiltEffect.IsTiltEnabled="true" Height="350" Width="400" Grid.ColumnSpan="3">
<Grid Height="350" Width="400" Margin="70,0,70,0" x:Name="Container1">
<Grid.Background>
<ImageBrush ImageSource="{Binding ImageCollection[0]}" Stretch="Uniform" AlignmentX="Left" AlignmentY="Center"/>
</Grid.Background>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Tap">
<i:InvokeCommandAction Command="{Binding ImageTapCommand}" CommandParameter="CONTAINER0"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Grid>
</Border>
Run Code Online (Sandbox Code Playgroud)
同样我使用4边框显示我最近的图像.
在我的ViewModel中,我使用以下方法从隔离存储中读取图像.
public Stream GetFileStream(string filename, ImageLocation location)
{
try
{
lock (SyncLock)
{
if (location == ImageLocation.RecentImage)
{
filename = Constants.IsoRecentImage + @"\" + filename;
}
using (var iSf = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!iSf.FileExists(filename)) return null;
var fs = iSf.OpenFile(filename, FileMode.Open, FileAccess.Read);
return fs;
}
}
}
catch (Exception ex)
{
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
在获得流之后,我将使用下面编写的方法四构建WritableBitmap用于UI绑定
private WriteableBitmap BuildImage(Stream imageStream)
{
using (imageStream)
{
var image = new BitmapImage();
image.SetSource(imageStream);
return new WriteableBitmap(image);
}
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我的问题是在我的页面导航和导出两到三次之后.应用程序在BuildImage()方法崩溃,我正在使用"image.SetSource(imageStream);" 方法.我尝试了许多替代方案但失败了 我得到的例外是"System.OutOfMemoryException"
我尝试使用Image控件而不是Image画笔.
我尝试了Bitmap而不是WritableBitmap等,但结果是一样的.
如果我使用小图片,应用程序崩溃率将降低.但是通过相机拍摄的图像的崩溃率很高.
我正在尝试解决这个问题的最后一周,但没有找到任何替代方案来解决这个问题.
我找到了一个谈论类似问题的链接但是没有多少人来解决这个问题
Try this,
var bitmapImage = new BitmapImage();
bitmapImage.SetSource(stream);
bitmapImage.CreateOptions = BitmapCreateOptions.None;
var bmp = new WriteableBitmap((BitmapSource) bitmapImage);
bitmapImage.UriSource = (Uri) null;
return bmp;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
752 次 |
| 最近记录: |