下载&保存图形

时间:2012-04-24 14:37:33

标签: java image graphics file-io javax.imageio

我在保存已加载的图片时遇到了困难。图片保存在该程序所在的同一文件夹下。错误不断出现。错误屏幕在

下面

错误

---------- Capture Output ----------
>"C:\Program Files\Java\jdk1.6.0_22\bin\java.exe" loadapicture
java.lang.NoClassDefFoundError: loadapicture
Caused by: java.lang.ClassNotFoundException: loadapicture
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: loadapicture.  Program will exit.
Exception in thread "main" 
> Terminated with exit code 1.

我的节目

import hsa.*;
import java.awt.*;
// Look at all of these extra imports needed for a picture file
import java.io.File;
import java.io.IOException;
import java.awt.image.*;
import javax.imageio.*;


public class loadapicture{
    public static void main(String[] args){
        Console con = new Console();

        // Variables need to open a picture file
        File tictactoefile;
        BufferedImage tictactoeimage;
        tictactoefile = null;
        tictactoeimage = null;

        // Now that the variables are created.. Time to load the picture into the variables
        // BTW  You need to load the file using a block called try/catch
        // Becuase if the file does not exist, you need to catch the error
        // You can use jpg, gif, and bmp

        try{
            // Trying to open the file and loading it
            tictactoefile = new File("");
            tictactoeimage = ImageIO.read( owin.jpeg);

        }catch(IOException e){
            // If the file is not found, this will happen
            con.println("ERROR... IMAGE FILE NOT FOUND"); 
        }


        con.drawImage(tictactoeimage, 100, 100, null);

        // Yes you can do all of this in a method
}
}

如何下​​载&正确保存图像?

1 个答案:

答案 0 :(得分:2)

我想你只需要指定你班级的路径

"C:\Program Files\Java\jdk1.6.0_22\bin\java.exe" -classpath <path to your class> loadapicture