如何将文件类型转换为图像?

问题描述

我有以下代码

  unsigned char data[9] = "tJQVfvcj";
  uint64_t num = 1732462110473334785;

  unsigned char concat[28];
  sprintf(concat,"%s%" PRId64 "",data,num);

我想将其从File obraz = new File("C:\\Users\\ender\\Pictures\\logo.jpg"); 转换成Image。我该怎么办?

解决方法

您可以这样做:

try {
    File obraz = new File("C:\\Users\\ender\\Pictures\\logo.jpg");
    Image image = ImageIO.read(obraz);
} catch (IOException ex) {
    ex.printStackTrace();
}

使用ImageIO帮助程序类。

,

尝试一下:

Image img = null;
try {
    img = ImageIO.read(new File("C:\\Users\\ender\\Pictures\\logo.jpg"));
} 
catch (IOException e) {}

Documentation