I am trying to capture a Image and then send that on image to parse.com including other object values. To make it short I was sending the image to parse.com as soon as I capture image without even Button_click event. it is working but not what i want. I want to save the memory stream and then use the saved stream to send on parse.com on button click with the other object variables.
This is the code where I am capturing the image and sending it to 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();
}
}
}
this is my button click code where I want to send that image on click instead of sending it directly after capture. i want to save the image stream if possible and then send it to parse.com on button click.
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
}
}
}
on button click
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();
}