out.close();
return out.toByteArray();
}
public ImageResource getImageResource(String uriStr) {
ImageResource resource = null;
if (ImageUtil.isEmbeddedBase64Image(uriStr)) {
resource = loadEmbeddedBase64ImageResource(uriStr);
} else {
uriStr = resolveURI(uriStr);
resource = (ImageResource) _imageCache.get(uriStr);
if (resource == null) {
InputStream is = resolveAndOpenStream(uriStr);
if (is != null) {
try {
URI uri = new URI(uriStr);
if (uri.getPath() != null && uri.getPath().toLowerCase().endsWith(".pdf")) {
PdfReader reader = _outputDevice.getReader(uri);
PDFAsImage image = new PDFAsImage(uri);
Rectangle rect = reader.getPageSizeWithRotation(1);
image.setInitialWidth(rect.getWidth() * _outputDevice.getDotsPerPoint());
image.setInitialHeight(rect.getHeight() * _outputDevice.getDotsPerPoint());
resource = new ImageResource(uriStr, image);
} else {
Image image = Image.getInstance(readStream(is));
scaleToOutputResolution(image);
resource = new ImageResource(uriStr, new ITextFSImage(image));
}
_imageCache.put(uriStr, resource);
} catch (Exception e) {
XRLog.exception("Can't read image file; unexpected problem for URI '" + uriStr + "'", e);
} finally {
try {
is.close();
} catch (IOException e) {
// ignore
}
}
}
}
if (resource != null) {
resource = new ImageResource(resource.getImageUri(), (FSImage) ((ITextFSImage) resource.getImage()).clone());
} else {
resource = new ImageResource(uriStr, null);
}
}
return resource;
}