【问题标题】:Sending a raw image to my database (parse), how should I send it?将原始图像发送到我的数据库(解析),我应该如何发送它?
【发布时间】:2016-05-13 06:58:28
【问题描述】:

一步一步地解决我的问题。我现在有一个原始图像数据,最后一步是将其发送到我的数据库,在这种情况下我使用 Parse。这是到目前为止的代码:

具有 Selectpicture 功能的视图模型以及我如何获取原始图像(有效):

public async Task SelectPicture()
    {
        Setup ();
        ImageSource = null;

        try
        {
            var mediaFile = await _Mediapicker.SelectPhotoAsync(new CameraMediaStorageOptions
                {
                    DefaultCamera = CameraDevice.Front,
                    MaxPixelDimension = 400
                });

            VideoInfo = mediaFile.Path;
            ImageSource = ImageSource.FromStream(() => mediaFile.Source);

            imageData = ReadStream(mediaFile.Source);

        }
        catch (System.Exception ex)
        {
            Status = ex.Message;
        }
    }

我尝试将图片发送到我的数据库的页面以及用户可以看到他们选择的图片的页面,这就是我卡住的地方:

private async void btnPickPicture_Clicked (object sender, EventArgs e)
    {
        await MyViewModel.SelectPicture ();
        imgPicked.Source = MyViewModel.ImageSource; //my image x:name in xaml
        System.Diagnostics.Debug.WriteLine (imgPicked.Source);

    }
 //Below I send it to my parse and in parse they save it as a "File". This is the part where I am not sure how to get it right. I have to pass it as a byte but Iam not sure how to execute it.

async void SendDataClick (object sender, EventArgs args) 
    { 
        var createResult = await parseAPI.createInfo 
            ( MyViewModel.ImageData );
    }

要解析的代码:

static public async Task<bool> createInfo (byte [] thePicture)

【问题讨论】:

  • 旁注:如果您没有听说过,Facebook 正在关闭 Parse,因此对于新的开发,您可能需要考虑其他服务...blog.parse.com/announcements/moving-on
  • 是的,我知道。但由于我现在主要是在努力学习,所以我将它用于我的锻炼项目。

标签: c# image forms xamarin


【解决方案1】:

使用ParseFile 保存图像和二进制数据

// pass the ImageData from your VM into the constructor
ParseFile file = new ParseFile("image.jpg", MyViewModel.ImageData);

// save the file
file.SaveAsync();

【讨论】:

  • 我通过 REST API 使用解析,因此我认为这不适用于我的特定情况。
  • 所以我需要发送一个 URL 什么的?尝试了一下,但无处可去。
  • 我的解析数据库已经设置好了,我只需要在我的:SendDataClick 函数(最后一段代码)中以正确的方式发送它
  • 尝试像这样发送它:( MyViewModel.ImageData );但由于我在我的 parseprofile 中将它作为 ImageSource,我无法将它作为字节发送,因为它需要图像
猜你喜欢
  • 2019-11-06
  • 1970-01-01
  • 2014-05-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多