我正在用Java进行Jpeg压缩来压缩图像,然后在存储之前调整它们的大小.我将存储高度保持为480,并根据宽高比计算高度,因此要保持原始的高宽比相同.
这是我正在使用的代码
String inputImagePath = "1.JPG";
String outputImagePath = "Test Compression\\" + "1.JPG";
File imageFile = new File(inputImagePath);
File compressedImageFile = new File(outputImagePath);
int height = 640;
System.out.print("Conversion Start!\n");
if (imageFile != null)
{
InputStream is = new FileInputStream(imageFile);
OutputStream os = new FileOutputStream(compressedImageFile);
float quality = 0.2 f;
BufferedImage image = ImageIO.read(is);
double aspectRatio = (double) image.getWidth() / image.getHeight();
width = (int)(height * aspectRatio);
System.out.println("Original height = " + image.getHeight() + " Origi