Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.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# 将图像上载为解析文件_C#_Wpf_Parse Platform - Fatal编程技术网

C# 将图像上载为解析文件

C# 将图像上载为解析文件,c#,wpf,parse-platform,C#,Wpf,Parse Platform,我正试图从我的WPF应用程序中上传一个select图像文件以存储在Parse上,但是我在任何地方都找不到执行此操作的正确方法 目前,我已经从“OpenFileDialog”中选择了我的图像,并将该图像的路径存储在文本框中 现在如何将此文件上载到Parse 我熟悉解析,在Objective-C中保存字符串、图像、视频等方面没有问题,但我一辈子都想不出如何在C#中的WPF应用程序中实现这一点 非常感谢您的帮助。下面是一段代码,用于加载图像文件并将数据保存到字节数组中 private byte[] L

我正试图从我的WPF应用程序中上传一个select图像文件以存储在Parse上,但是我在任何地方都找不到执行此操作的正确方法

目前,我已经从“OpenFileDialog”中选择了我的图像,并将该图像的路径存储在文本框中

现在如何将此文件上载到Parse

我熟悉解析,在Objective-C中保存字符串、图像、视频等方面没有问题,但我一辈子都想不出如何在C#中的WPF应用程序中实现这一点


非常感谢您的帮助。

下面是一段代码,用于加载图像文件并将数据保存到字节数组中

private byte[] LoadByteArrayFromFile(string fileName)
{
    try
    {
        using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
        {
            byte[] byteArray = new byte[fs.Length];
            int bytesRead = 0;
            int bytesToRead = (int)fs.Length;

            while (bytesToRead > 0)
            {
                int read = file.Read(byteArray, bytesRead, bytesToRead);
                if (read == 0)
                    break;
                bytesToRead -= read;
                bytesRead += read;
            }

            return byteArray;
        }
    }
    catch (Exception ex)
    {
        return null;
    }
}
所以你首先要得到数据

byte[] data = LoadByteArrayFromFile(filename); //OpenFileDialog.Path, full path to the image
然后,构建-您应该熟悉其余步骤

if (data != null)
{
    ParseFile file = new ParseFile(System.IO.Path.GetFileName(filename), data); 
    await file.SaveAsync();
    //then assign the ParseFile into a ParseObject, like the doc says...
}

你绝对是个传奇人物。非常感谢你。