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

GetITextSharpImageFromImageFile() public static method

Gets an image's file path and returns an instance of iTextSharp.text.Image
public static GetITextSharpImageFromImageFile ( this imageFilePath, bool cacheImages = true ) : Image
imageFilePath this Image's file path
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 GetITextSharpImageFromImageFile(this string imageFilePath, bool cacheImages = true)
        {
            if (!cacheImages)
                return iTextSharp.text.Image.GetInstance(imageFilePath).checkImage();

            iTextSharp.text.Image image;
            var pathHash = imageFilePath.ToLowerInvariant().MD5Hash();
            if (_imageFilesCache.TryGetValue(pathHash, out image))
                return image.checkImage();

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