PdfRpt.Core.Helper.PdfImageHelper.GetITextSharpImageFromByteArray C# (CSharp) Method

GetITextSharpImageFromByteArray() public static method

Converts an array of bytes/blobs of an image file to an instance of iTextSharp.text.Image
public static GetITextSharpImageFromByteArray ( this data, bool cacheImages = true ) : Image
data this blob data
cacheImages bool If true, the image bytes will be added to the PDF only once, not per each new instance. Therefore the result won't be a bloated PDF file. Choose this option if there are many similar images in your data source.
return iTextSharp.text.Image
        public static iTextSharp.text.Image GetITextSharpImageFromByteArray(this byte[] data, bool cacheImages = true)
        {
            if (!cacheImages)
                return iTextSharp.text.Image.GetInstance(data).checkImage();

            iTextSharp.text.Image image;
            var pathHash = data.MD5Hash();
            if (_imageBytesCache.TryGetValue(pathHash, out image))
                return image.checkImage();

            image = iTextSharp.text.Image.GetInstance(data);
            _imageBytesCache.Add(pathHash, image);
            return image.checkImage();
        }