用JAVA读取图片的三种方式

版权声明:ThomasKwan https://blog.csdn.net/thomassamul/article/details/86528888
import java.net.*;//for URL
import java.io.*;//for catch (IOException e),File,InputStream, BufferedInputStream,and FileInputStream ect
public class HelloJava{
   public static void main (String[] args){
   Image image = null;
    try {
        // Read from a file
        File sourceimage = new File("source.gif");  //source.gif图片要与HelloJava.java同在一目录下
        image = ImageIO.read(sourceimage);
    
        // Read from an input stream
        InputStream is = new BufferedInputStream(
           new FileInputStream("mid.jpg"));  //mid.jpg图片要与HelloJava.java同在一目录下
        image = ImageIO.read(is);
    
        // Read from a URL
        URL url = new URL("http://www.javaworld.com/images/012407-tipsbox.jpg");
        image = ImageIO.read(url);
    } catch (IOException e) {
    }
    
}

猜你喜欢

转载自blog.csdn.net/thomassamul/article/details/86528888
今日推荐