Imagem em escala borrada no PDFBox
Estou tentando dimensionar uma imagem com tamanho = 2496 x 3512 em um documento PDF. Estou usando o PDFBox para gerá-lo, mas a imagem em escala acaba desfocada.
Aqui estão alguns trechos:
PDF Tamanho da página (A4) retornado por page.findMediaBox (). CreateDimension (): java.awt.Dimension [width = 612, height = 792]
Então eu calculo a dimensão dimensionada com base no tamanho da página versus tamanho da imagem que retorna: java.awt.Dimension [width = 562, height = 792] Eu uso o código abaixo para calcular a dimensão dimensionada:
public static Dimension getScaledDimension(Dimension imgSize, Dimension boundary) {
int original_width = imgSize.width;
int original_height = imgSize.height;
int bound_width = boundary.width;
int bound_height = boundary.height;
int new_width = original_width;
int new_height = original_height;
// first check if we need to scale width
if (original_width > bound_width) {
//scale width to fit
new_width = bound_width;
//scale height to maintain aspect ratio
new_height = (new_width * original_height) / original_width;
}
// then check if we need to scale even with the new height
if (new_height > bound_height) {
//scale height to fit instead
new_height = bound_height;
//scale width to maintain aspect ratio
new_width = (new_height * original_width) / original_height;
}
return new Dimension(new_width, new_height);
}
E para realmente executar o dimensionamento da imagem, estou usando a API Image Scalr:
BufferedImage newImg = Scalr.resize(img, Scalr.Method.ULTRA_QUALITY, Scalr.Mode.FIT_EXACT,
scaledWidth, scaledHeight, Scalr.OP_ANTIALIAS);
Minha pergunta é o que estou fazendo de errado? Uma imagem grande não deve ser desfocada quando dimensionada para um tamanho menor. Isso está relacionado à resolução / tamanho da página PDF?
Obrigado,
Gyo