1
下面的代碼調整圖像大小。不幸的是,垂直圖像的圖像在邊上有黑條。它看起來好像透明的或空白的空間充滿了黑色。我試着將背景顏色設置爲白色,並使用alphaRGB,但似乎無法動搖它。無法調整圖像大小並保持透明度
OrderProductAssetEntity orderProductAssetEntity = productAssets.get(jobUnitEntity.getId());
File asset = OrderProductAssetService.getAssetFile(orderProductAssetEntity);
if (asset.exists()) {
//resize the asset to a smaller size
BufferedImage resizedImage = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
Graphics2D g = resizedImage.createGraphics();
g.setBackground(Color.WHITE);
g.drawImage(ImageIO.read(asset), 0, 0, width, height, null);
g.dispose();
jobUnitImages.put(orderProductAssetEntity.getOriginalLocation(), new PDJpeg(document, resizedImage));
} else {
jobUnitImages.put(orderProductAssetEntity.getOriginalLocation(), null);
}
完美!我用'g.drawImage(...)'謝謝! – Webnet