Example #1
0
        /// <summary>
        /// Converts a byte array to a UIImage object.
        /// </summary>
        /// <param name="bytes">An array of bytes.</param>
        /// <param name="decompress">
        /// True if the image should be decompressed, otherwise false. This would be useful when converting
        /// a byte array into a UIImage for a UIImageView on a background thread. The image would otherwise get
        /// decompressed by the UIImageView synchronously on the UI thread. Decompressing it on a background
        /// thread will create a smoother UX.
        /// </param>
        /// <returns>A new UIImage instance.</returns>
        public static UIImage FromBytes(byte[] bytes, bool decompress = false)
        {
            UIImage image = UIImage.LoadFromData(NSData.FromArray(bytes));

            return
                (decompress
                ? image.Decompress()
                : image);
        }