javajavax.imageio

The method read(File) in the type ImageIO is not applicable for the arguments (String)


So when I replace the urlImage to an actual image path e.g. "BufferedImage image = ImageIO.read("F:/Java/data/photo.jpg") on the first line of the code it return the following error "The method read(File) in the type ImageIO is not applicable for the arguments (String)" I tried different things but it didn't work, it may sound obvious, I just wasn't able to convert the String type to File.

BufferedImage image = ImageIO.read(urlImage);
int x;
int y;
int c = image.getRGB(x,y);
int  red = (c & 0x00ff0000) >> 16;
int  green = (c & 0x0000ff00) >> 8;
int  blue = c & 0x000000ff;
// and the Java Color is ...
Color color = new Color(red,green,blue);

Solution

  • The method read(File) in the type ImageIO is not applicable for the arguments (String)

    is a pretty clear error. You are passing an String where you need to pass a File. Just do:

    BufferedImage image = ImageIO.read(new File(urlImage));