Hololens/Lib/ImageConversion.cs
//########################################################################################
/// <summary>
/// Convert to the bitmap object to a jpeg suence of bytes
/// </summary>
/// <param name="bitmap"> SoftwareBitmap object </param>
/// <returns> a byte array jpeg image </returns>
Convert to the bitmap object to a jpeg suence of bytes
Convert to the bitmap object to a jpeg suence of bytes
public static async Task<byte[]> ToJPG(SoftwareBitmap bitmap)
        {
            if (bitmap != null)
            {
                using (var stream_buffer = new InMemoryRandomAccessStream())
                {
                    BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, stream_buffer); 
                    encoder.SetSoftwareBitmap(bitmap);
                    await encoder.FlushAsync(); 
                    byte[] jpg = new byte[stream_buffer.Size]; 
                    await stream_buffer.ReadAsync(jpg.AsBuffer(), (uint)stream_buffer.Size, InputStreamOptions.None); 
                    return jpg;
                }
            }
            else
            {
                return null;
            }
        }
public static async Task < byte [ ] > ToJPG ( SoftwareBitmap bitmap ) { if ( bitmap != null ) { using ( var stream_buffer = new InMemoryRandomAccessStream ( ) ) { BitmapEncoder encoder = await BitmapEncoder . CreateAsync ( BitmapEncoder . JpegEncoderId , stream_buffer ) ; encoder . SetSoftwareBitmap ( bitmap ) ; await encoder . FlushAsync ( ) ; byte [ ] jpg = new byte [ stream_buffer . Size ] ; await stream_buffer . ReadAsync ( jpg . AsBuffer ( ) , ( uint ) stream_buffer . Size , InputStreamOptions . None ) ; return jpg ; } } else { return null ; } }
Convert to the bitmap object to a jpeg suence of bytes
Convert to the bitmap object to a jpeg suence of bytes
// create encoder, bind to it software bitmap image and encode // stream buffer is used by the encoder // encode and store data in stream buffer // the expected byte array // data transfer from buffer to byte array
a byte array jpeg image
a byte array jpeg image
bitmap
SoftwareBitmap
None