java - 下载并保存图形

标签 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
}
}

如何正确下载并保存图片?

最佳答案

我想你只需要指定你的类的路径

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

关于java - 下载并保存图形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10300181/

相关文章:

ruby-on-rails - 如何在不先将文件复制到服务器的情况下在 S3 上压缩/tar 文件?

c++ - 内存使用和最小化

python - 使用 Python 确定图像是否存在于更大的图像中,如果存在,则找到它

java - 设置 Spring Archetype 时重复出现的问题

java - FileInputStream 负向跳过

java - 从 android 中的多个正在运行的应用程序检测声音级别

image - 如何相对于另一个轴定位图形中的轴?

python - 类型错误 : ord() expected a character, 但找到长度为 0 的字符串

java - 无法在另一个矩形上绘画

java - 什么是在java中解析数学表达式的好库?