public static GetITextSharpImageFromByteArray ( this data, bool cacheImages = true ) : |
||
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 |
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();
}