【问题标题】:How can you get the pixel dimensions of a jpg in java?如何在 java 中获取 jpg 的像素尺寸?
【发布时间】:2012-07-11 20:46:57
【问题描述】:

我需要找到一种方法来计算图像的长度和宽度(这是一个 .jpg)我有文件的长度,但它没有用,因为我想创建一个数组来存储有关信息我正在使用的图像文件的每个像素。

public void getImageData(){
    File f= new File("myPicture.jpg");
    this.length = (int) f.length();
        System.out.println("length of file = " + length);
        BufferedImage image = null;
        try {
            image = ImageIO.read(f);
            } 
        catch (IOException e) {

            e.printStackTrace();
            }

非常感谢您的帮助!

【问题讨论】:

标签: java image file


【解决方案1】:

一旦你得到BufferedImage,你就可以调用属性getWidth()getHeight()就可以了:

int imageWidth = image.getWidth();
int imageHeight = image.getHeight();

希望这会有所帮助。

【讨论】:

  • 如果答案有效,请选中他们答案旁边的绿色复选标记,以便人们知道您找到了解决方案!
猜你喜欢
  • 1970-01-01
  • 2010-11-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-07
  • 1970-01-01
  • 2020-10-25
  • 1970-01-01
相关资源
最近更新 更多