버튼을 클릭하면 캡처 이미지가 포함 된 메모리 스트림 보내기
-
20-12-2019 - |
문제
이미지를 캡처 한 다음 다른 객체 값을 포함하여 parse.com으로 이미지에서 해당 이미지를 보냅니다. 짧게 만들려면 button_click 이벤트라도 이미지를 캡처하자마자 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();
}
}
}
.
캡처 직후를 직접 보내는 대신 클릭하면 해당 이미지를 보내려는 코드를 클릭하십시오.가능한 경우 이미지 스트림을 저장 한 다음 Button colick에서 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
}
}
}
.
버튼 ON
를 클릭하십시오.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