javax.imageio
类 ImageIO
BufferedImage bi = ImageIO.read(resFile);//resFile --- InputStream
if(bi == null){
System.out.println(此文件不为图片文件);
}
try {//判断是否为图片文件并且返回图片的格式!
ImageInputStream iis = ImageIO.createImageInputStream(o);
// Find all image readers that recognize the image format
Iterator<ImageReader> iter = ImageIO.getImageReaders(iis);
if (!iter.hasNext()) {
// No readers found
return null;
}
// Use the first reader
ImageReader reader = iter.next();
// Close stream
iis.close();
// Return the format name
return reader.getFormatName();
}
加载一个图片:
ImageIcon(byte[] imageData, String description)