我在XAML中声明了一个图像,但希望将从C#显示的图像设置为独立存储中的图像

我在XAML中声明了一个图像,但希望将从C#显示的图像设置为独立存储中的图像,c#,windows-phone-7,xaml,C#,Windows Phone 7,Xaml,我可以在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" St

我可以在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>
当我输入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;    
    }
}
您需要设置
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;    
    }
}
您需要设置
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;    
    }
}