java中图片文件的判断
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)
本文来自博客园,作者:hjzqyx,转载请注明原文链接:https://www.cnblogs.com/hujunzheng/p/3989487.html