java获取本地image file的尺寸大小
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.ImageIcon;
public class TestImageSize {
public static void main(String[] args) {
String url = "/Users/yu/Pictures/ms_blog_icons.jpg";
Image img = new ImageIcon(url).getImage();
int width = img.getWidth(null);
int height = img.getHeight(null);
System.out.println("Image width: " + width);
System.out.println("Image height: " + height);
Image image = Toolkit.getDefaultToolkit().getImage(url);
int width1 = image.getWidth(null);
int height1 = image.getHeight(null);
System.out.println("Image width1: " + width1);
System.out.println("Image height1: " + height1);
}
}
No comments :
Post a Comment