Bom dia pessoal,
Estou com um problema ao setar imagens em jLabels, as imagens estão ficando totalmente pretas conforme anexo.
Segue trecho de código utilizado:
private void exibeFoto(String endImagem) {
ImageIcon imagem = new ImageIcon(UtilsImage.redimensionar(ImageIcon(endImagem).getImage(), 780 , 360, false));
jLFoto.setIcon(imagem);
}
public static Image redimensionar(Image imagem, int width, int height, boolean proporcional) {
//Se a imagem já tem as dimensões passadas retorna a imagem sem alteração
if ((imagem.getWidth(null) == width && imagem.getHeight(null) == height) ||
(width == 0 && height == 0)) {
return imagem;
}
if (proporcional) {
// Calculos necessários para manter as propoçoes da imagem, conhecido como "aspect ratio"
double thumbRatio = (double) width / (double) height;
int imageWidth = imagem.getWidth(null);
int imageHeight = imagem.getHeight(null);
double imageRatio = (double) imageWidth / (double) imageHeight;
if (thumbRatio < imageRatio) {
height = (int) (width / imageRatio);
} else {
width = (int) (height * imageRatio);
}
// Fim do cálculo
}
BufferedImage thumbImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics2D = thumbImage.createGraphics();
graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2D.drawImage(imagem, 0, 0, width, height, null);
return thumbImage;
}
Se alguém puder ajudar agradeço desde já.
