越来越接近解决我的问题,一步一步。我现在有一个原始图像数据,最后一步是将它发送到我的数据库,在这种情况下我使用Parse。这是到目前为止的代码:
具有Selectpicture功能的viewmodel以及我如何获取图像raw(有效):
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)
答案 0 :(得分:0)
使用ParseFile保存图像和二进制数据
// pass the ImageData from your VM into the constructor
ParseFile file = new ParseFile("image.jpg", MyViewModel.ImageData);
// save the file
file.SaveAsync();