public byte[] DecorateSourceWithMetaInformation(byte[] source, ImageMetaInformation information)
 {
     var metaData = ConvertMetaInformationToByteArray(information);
     return metaData
         .Concat(source)
         .ToArray();
 }
        public byte[] ConvertBitmapSourceToByteArray(BitmapSource bitmap)
        {
            if (bitmap == null) return null;

            var metaInformation = new ImageMetaInformation()
            {
                DpiX = bitmap.DpiX,
                DpiY = bitmap.DpiY,
                Width = bitmap.PixelWidth,
                Height = bitmap.PixelHeight,
                PixelFormat = bitmap.Format
            };

            var imageData = ConvertImageDataToByteArray(bitmap);
            return DecorateSourceWithMetaInformation(imageData, metaInformation);
        }
        static BitmapSource GenerateBitmapSource(ImageMetaInformation metaInformation, byte[] imageData)
        {
            var bytesPerPixel = (metaInformation.PixelFormat.BitsPerPixel + 7) / 8;
            var stride = bytesPerPixel * metaInformation.Width;

            return BitmapSource.Create(metaInformation.Width, metaInformation.Height, metaInformation.DpiX, metaInformation.DpiY, metaInformation.PixelFormat, null, imageData, stride);
        }
 byte[] ConvertMetaInformationToByteArray(ImageMetaInformation metaInformation)
 {
     return GeneralApi.StructureToByteArray(metaInformation);
 }
 private static IEnumerable<byte> ConvertMetaInformationToByteArray(ImageMetaInformation metaInformation)
 {
     return GeneralApi.StructureToByteArray(metaInformation);
 }