Parse.comにキャプチャ画像を含むメモリストリームをボタンをクリックします。
-
20-12-2019 - |
質問
私は画像をキャプチャしてから、他のオブジェクト値を含むparse.comに画像に送信しようとしています。 短くするために、私はimage_clickイベントでさえイメージをキャプチャするとすぐにimage.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