Domanda

Sto cercando di catturare un'immagine e quindi inviarlo sull'immagine a Parse.com, inclusi altri valori dell'oggetto. Per renderlo breve, stavo inviando l'immagine a Parse.com non appena ho acquisito un'immagine senza nemmeno un evento Button_Click.Sta funzionando ma non quello che voglio.Voglio salvare il flusso di memoria e quindi utilizzare il flusso salvato da inviare a Parse.com sul pulsante Fare clic con le altre variabili dell'oggetto.

Questo è il codice in cui sto catturando l'immagine e inviandolo a 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();
            }
        }
    }
.

Questo è il mio pulsante clic sul codice in cui voglio inviare quell'immagine sul clic anziché dall'invio direttamente dopo l'acquisizione.Voglio salvare il flusso di immagini se possibile e quindi inviarlo a Parse.com sul pulsante 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();
    }
.

È stato utile?

Soluzione

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();

    }
.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top