ImageIO.read getWiedth
时间: 2023-09-19 22:11:12 浏览: 97
`ImageIO.read` is a method in Java that reads an image from an input source and returns a `BufferedImage` object. To get the width of the image, you can use the `getWidth()` method on the `BufferedImage` object returned by `ImageIO.read`. Here is an example:
```java
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class ImageWidthExample {
public static void main(String[] args) {
try {
File imageFile = new File("image.jpg");
BufferedImage image = ImageIO.read(imageFile);
int width = image.getWidth();
System.out.println("Image width: " + width);
} catch (IOException e) {
e.printStackTrace();
}
}
}
```
In this example, we read an image file called "image.jpg" using `ImageIO.read`, and then use the `getWidth()` method to get the width of the image. The width is then printed to the console.
阅读全文