我可以在我的xaml中声明我的图像
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanelx" Grid.Row="1" Margin="0,0,0,0">
<Image x:Name="MyImage" Height="150" HorizontalAlignment="Left" Margin="141,190,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="200" />
</Grid>
Run Code Online (Sandbox Code Playgroud)
我可以通过.xaml.cs从孤立的存储中加载我的图像
void loadImage()
{
// The image will be read from isolated storage into the following byte array
byte[] data;
// Read the entire image in one go into a byte array
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream isfs = isf.OpenFile("0.jpg", FileMode.Open, FileAccess.Read))
{
data = new byte[isfs.Length];
isfs.Read(data, 0, data.Length);
isfs.Close();
}
}
MemoryStream ms = new MemoryStream(data);
BitmapImage bi = new BitmapImage();
bi.SetSource(ms);
Image image = new Image();
image.Height = bi.PixelHeight;
image.Width = bi.PixelWidth;
image.Source = bi;
}
Run Code Online (Sandbox Code Playgroud)
当我输入MyImage时.我找不到一种方法将其设置为我刚刚创建的图像.你们中的任何人都可以提出建议吗?
void loadImage() { // The image will be read from isolated storage into the following byte array
byte[] data;
// Read the entire image in one go into a byte array
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream isfs = isf.OpenFile("0.jpg", FileMode.Open, FileAccess.Read))
{
data = new byte[isfs.Length];
isfs.Read(data, 0, data.Length);
isfs.Close();
}
}
MemoryStream ms = new MemoryStream(data);
BitmapImage bi = new BitmapImage();
bi.SetSource(ms);
MyImage.Source = bi;
}
}
Run Code Online (Sandbox Code Playgroud)
你需要设置MyImage.Source = bi;.就是这样
还有一点重构:
void loadImage() {
BitmapImage bi = new BitmapImage();
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream isfs = isf.OpenFile("0.jpg", FileMode.Open, FileAccess.Read))
{
bi.SetSource(isfs);
}
}
MyImage.Source = bi;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
464 次 |
| 最近记录: |