小编vam*_*ddy的帖子

Java:BufferedImage 上的 getHeight() 返回图像宽度,getWidth() 返回图像高度

我正在使用 Java 进行 Jpeg 压缩来压缩图像,然后在存储之前调整它们的大小。我将存储高度保持为480并根据纵横比计算height,以便保持原始height:width比率相同。

这是我正在使用的代码

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 = " + …
Run Code Online (Sandbox Code Playgroud)

java metadata image

5
推荐指数
1
解决办法
2731
查看次数

标签 统计

image ×1

java ×1

metadata ×1