import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class JavaImageIOTest
{
public JavaImageIOTest()
{
try
{
// the line that reads the image file
BufferedImage image = ImageIO.read(new File("C:\ Users \ Public \ Pictures\ Sample Pictures\ Penguins.jpg"));
// work with the image here ...
}
catch (IOException e)
{
// log the exception
// re-throw if desired
}
}
public static void main(String[] args)
{
new ImageIOTest();
}
}
为此我获取路径规范错误.....所以你能告诉我读取图像并显示它的确切代码
答案 0 :(得分:1)
您需要在文件规范中使用双斜杠
BufferedImage image = ImageIO.read(new File("C:\\Users\\Public\\Pictures\\Sample Pictures\\Penguins.jpg"));