Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在java中获得jpg的像素尺寸?_Java_Image_File - Fatal编程技术网

如何在java中获得jpg的像素尺寸?

如何在java中获得jpg的像素尺寸?,java,image,file,Java,Image,File,我需要找到一种方法来计算图像的长度和宽度(即.jpg),我有文件的长度,但它没有用,因为我想制作一个数组来存储关于我正在使用的图像文件的每个像素的信息 public void getImageData(){ File f= new File("myPicture.jpg"); this.length = (int) f.length(); System.out.println("length of file = " + length); Buffe

我需要找到一种方法来计算图像的长度和宽度(即.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();
            }

非常感谢您的帮助

一旦获得
缓冲区图像
,就可以调用属性并对其执行以下操作:


希望这有帮助。

一旦您获得了
缓冲区图像
,您就可以调用属性并对其执行以下操作:


希望这有帮助。

可能重复可能重复如果答案有效,请勾选答案旁边的绿色复选标记,以便人们知道您找到了解决方案!如果答案有效,请勾选答案旁边的绿色复选标记,以便人们知道您找到了解决方案!
int imageWidth = image.getWidth();
int imageHeight = image.getHeight();