如何使用Java调整图像大小?
我需要调整PNG,JPEG和GIF文件的大小。如何使用Java做到这一点?
回答:
加载图像后,你可以尝试:
BufferedImage createResizedCopy(Image originalImage, int scaledWidth, int scaledHeight,
boolean preserveAlpha)
{
System.out.println("resizing...");
int imageType = preserveAlpha ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
BufferedImage scaledBI = new BufferedImage(scaledWidth, scaledHeight, imageType);
Graphics2D g = scaledBI.createGraphics();
if (preserveAlpha) {
g.setComposite(AlphaComposite.Src);
}
g.drawImage(originalImage, 0, 0, scaledWidth, scaledHeight, null);
g.dispose();
return scale
以上是 如何使用Java调整图像大小? 的全部内容, 来源链接: utcz.com/qa/421611.html