Domanda

Dopo che un'immagine viene scattata con CameraCaptureTask dovrebbe essere caricato sul server.Il jpg caricato sul lato server sembra avere dimensioni del file corretto ma è danneggiata.Anche imageBuffer sembra avere tutti i byte su 0. qualsiasi idea di ciò che è sbagliato nel codice qui sotto?

if (bitmapImage != null) {
    // create WriteableBitmap object from captured BitmapImage
    WriteableBitmap writeableBitmap = new WriteableBitmap(bitmapImage);

    using (MemoryStream ms = new MemoryStream())
    {
        writeableBitmap.SaveJpeg(ms, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 0, 100);

        imageBuffer = new byte[ms.Length];
        ms.Read(imageBuffer, 0, imageBuffer.Length);
        ms.Dispose();
    }                
}
.

È stato utile?

Soluzione

Il metodo Salvajpeg modifica la posizione corrente del flusso.Per preservare correttamente il contenuto del flusso, è necessario leggerlo dall'inizio (I.e. Imposta posizione su 0).Prova questo:

if (bitmapImage != null) {
    // create WriteableBitmap object from captured BitmapImage
    WriteableBitmap writeableBitmap = new WriteableBitmap(bitmapImage);

    using (MemoryStream ms = new MemoryStream())
    {
        writeableBitmap.SaveJpeg(ms, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 0, 100);

        ms.Position = 0;
        imageBuffer = new byte[ms.Length];
        ms.Read(imageBuffer, 0, imageBuffer.Length);
        ms.Dispose();
    }                
}
.

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