如何将文件类型转换为图像?
How to convert File type to Image?
我有这个代码:
File obraz = new File("C:\Users\ender\Pictures\logo.jpg");
我想将其从 java.awt
转换为 Image
。我应该怎么做?
你可以这样做:
try {
File obraz = new File("C:\Users\ender\Pictures\logo.jpg");
Image image = ImageIO.read(obraz);
} catch (IOException ex) {
ex.printStackTrace();
}
使用 ImageIO 助手 class。
试试这个:
Image img = null;
try {
img = ImageIO.read(new File("C:\Users\ender\Pictures\logo.jpg"));
}
catch (IOException e) {}
我有这个代码:
File obraz = new File("C:\Users\ender\Pictures\logo.jpg");
我想将其从 java.awt
转换为 Image
。我应该怎么做?
你可以这样做:
try {
File obraz = new File("C:\Users\ender\Pictures\logo.jpg");
Image image = ImageIO.read(obraz);
} catch (IOException ex) {
ex.printStackTrace();
}
使用 ImageIO 助手 class。
试试这个:
Image img = null;
try {
img = ImageIO.read(new File("C:\Users\ender\Pictures\logo.jpg"));
}
catch (IOException e) {}