发送内存流,其中包含捕获图像到parse.com按钮单击
-
20-12-2019 - |
题
我正在尝试捕获图像,然后在图像上发送到parse.com,包括其他对象值。 要使它短暂,我一旦我捕获图像,就会将图像发送到Parse.com。它正在工作,但不是我想要的。我想保存内存流,然后使用已保存的流在Parse.com上发送按钮,单击其他对象变量。
这是我捕获图像并将其发送到parse.com的代码
private async void cameraCapture_Completed(object sender, PhotoResult e)
{
if (e.TaskResult != TaskResult.OK) return;
var capturedPhoto = new BitmapImage();
capturedPhoto.SetSource(e.ChosenPhoto);
ImgView.Source = capturedPhoto;
PictureFileName = today.ToString();
{
using (var memoryStream = new MemoryStream())
{
// Get a stream of the captured photo
var writableBitmap = new WriteableBitmap(capturedPhoto);
writableBitmap.SaveJpeg(memoryStream, capturedPhoto.PixelWidth, capturedPhoto.PixelHeight, 0, 100);
PhotoResult photoResult = e as PhotoResult;
photoResult.ChosenPhoto.CopyTo(memoryStream);
memoryStream.Position = 0; // Rewind the stream
byte[] myPicArray = memoryStream.ToArray();
ParseFile ImageFile = new ParseFile(PictureFileName, myPicArray);
await ImageFile.SaveAsync();
var image = new ParseObject("ImageUpload");
image["photo"] = ImageFile;
image["description"] = TextBox.Text;
await image.SaveAsync();
}
}
}
.
这是我的按钮单击代码,我要在拍摄时发送该映像,而不是在捕获后直接发送它。如果可能,我想保存图像流,然后将其发送到parse.com上按钮单击。
private async void Btn_Click(object sender, RoutedEventArgs e)
{
var image = new ParseObject("ImageUpload");
image["photo"] = imageFile; //how to bring that memory stream here ???
image["description"] = TxtBox.Text;
await image.SaveAsync();
}
. 解决方案
private void cameraCapture_Completed(object sender, PhotoResult e)
{
if (e.TaskResult != TaskResult.OK) return;
var capturedPhoto = new BitmapImage();
capturedPhoto.SetSource(e.ChosenPhoto);
ImgView.Source = capturedPhoto;
FileName = today.ToString();
{
using (var memoryStream = new MemoryStream())
{
// Get a stream of the captured photo
var writableBitmap = new WriteableBitmap(capturedPhoto);
writableBitmap.SaveJpeg(memoryStream, capturedPhoto.PixelWidth, capturedPhoto.PixelHeight, 0, 50);
PhotoResult photoResult = e as PhotoResult;
photoResult.ChosenPhoto.CopyTo(memoryStream);
memoryStream.Position = 0; // Rewind the stream
myPic = memoryStream.ToArray(); // byte[] myPic; has been decleared in inital
}
}
}
.
在按钮上单击
private async void BtnPost_Click(object sender, RoutedEventArgs e)
{
ParseFile ImageFile = new ParseFile(FileName, myPic);
await ImageFile.SaveAsync();
var imageUpload = new ParseObject("ImageUpload ");
imageUpload["photo"] = ImageFile;
await imageUpload.SaveAsync();
}
. 不隶属于 StackOverflow