Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 加载本地映像以用于Windows 7 Phone应用程序测试_C#_Image_Windows Phone 7_Load - Fatal编程技术网

C# 加载本地映像以用于Windows 7 Phone应用程序测试

C# 加载本地映像以用于Windows 7 Phone应用程序测试,c#,image,windows-phone-7,load,C#,Image,Windows Phone 7,Load,总之,我对Windows Phone非常陌生,真的不知道该在哪里使用它。我不想将一些测试图像加载到我的Windows phone应用程序中(仅用于测试目的)。在我的机器上,我有一些JPEG,我想把它们加载到画布,画布本身包含一个图像。我知道你可以像这样从本地存储加载 private void LoadFromLocalStorage(string imageFileName, string imageFolder) { var isoFile = IsolatedStorageFile.

总之,我对Windows Phone非常陌生,真的不知道该在哪里使用它。我不想将一些测试图像加载到我的Windows phone应用程序中(仅用于测试目的)。在我的机器上,我有一些JPEG,我想把它们加载到
画布
,画布本身包含一个
图像
。我知道你可以像这样从本地存储加载

private void LoadFromLocalStorage(string imageFileName, string imageFolder)
{
    var isoFile = IsolatedStorageFile.GetUserStoreForApplication();
    if (!isoFile.DirectoryExists(imageFolder))
    {
        isoFile.CreateDirectory(imageFolder);
    }

    string filePath = Path.Combine(imageFolder, imageFileName);
    using (var imageStream = isoFile.OpenFile(
        filePath, FileMode.Open, FileAccess.Read))
    {
        var imageSource = PictureDecoder.DecodeJpeg(imageStream);
        image.Source = imageSource;
    }
}

但是如何将图像从我的机器中存储到独立的存储中呢?对不起,我是个真正的noob:[。

最简单的方法是使用某种隔离存储浏览器:


假设应用程序目录中的图像文件夹中有图像。请确保将生成操作设置为“内容”


也许你正在试图做的是过分的。你不能添加一些图像到你的项目中,并将其分配到源属性吗?那将是很好的,但我可以找到一个使用JPEG的例子。如果你能提供一个很好的例子!你能扩展你的答案吗?我现在在使用lin加载图像时遇到一些问题e
streamresourceinfosr=Application.GetResourceStream(新Uri(f,UriKind.Relative));
?它正在将
sr
设置为
null
,我不知道为什么,因为我有像
newURI(/Icons/appbar.questionmark.rest.png),UriKind.Relative)这样的行
public class Storage
{
    public void SaveFilesToIsoStore()
    {
        //These files must match what is included in the application package,
        //or BinaryStream.Dispose below will throw an exception.
        string[] files = {
        "images/img1.jpg", "images/img2.png"
    };

        IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();

        if (files.Length > 0)
        {
            foreach (string f in files)
            {
                StreamResourceInfo sr = Application.GetResourceStream(new Uri(f, UriKind.Relative));
                using (BinaryReader br = new BinaryReader(sr.Stream))
                {
                    byte[] data = br.ReadBytes((int)sr.Stream.Length);
                    SaveToIsoStore(f, data);
                }
            }
        }
    }

    private void SaveToIsoStore(string fileName, byte[] data)
    {
        string strBaseDir = string.Empty;
        string delimStr = "/";
        char[] delimiter = delimStr.ToCharArray();
        string[] dirsPath = fileName.Split(delimiter);

        //Get the IsoStore.
        IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();

        //Re-create the directory structure.
        for (int i = 0; i < dirsPath.Length - 1; i++)
        {
            strBaseDir = System.IO.Path.Combine(strBaseDir, dirsPath[i]);
            isoStore.CreateDirectory(strBaseDir);
        }

        //Remove the existing file.
        if (isoStore.FileExists(fileName))
        {
            isoStore.DeleteFile(fileName);
        }

        //Write the file.
        using (BinaryWriter bw = new BinaryWriter(isoStore.CreateFile(fileName)))
        {
            bw.Write(data);
            bw.Close();
        }
    }

}
 private void Application_Launching(object sender, LaunchingEventArgs e)
    {
        Storage sg = new Storage();
        sg.SaveFilesToIsoStore();
    }