user1088595
user1088595

Reputation: 151

Using buffered image converting using compression

Attempting to read in a buffered bmp image and then convert with compression to jpeg. Something is wrong with the buffered image line. Thank you, any help is appreciated.

public void jpegconvert(String Fname, String Crate)
{

BufferedImage image =  ImageIO.read(Fname);

Iterator<ImageWriter> i = ImageIO.getImageWritersByFormatName("jpeg"); 

// Just get the first JPEG writer available 
ImageWriter jpegWriter = i.next(); 

// Set the compression quality to 0.8 
ImageWriteParam param = jpegWriter.getDefaultWriteParam(); 
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); 
param.setCompressionQuality(0.8f); 

// Write the image to a file 
FileImageOutputStream out = new FileImageOutputStream(new File("newimage.jpg")); 
jpegWriter.setOutput(out); 
jpegWriter.write(null, new IIOImage(image, null, null), param); 
jpegWriter.dispose(); 
out.close();
}
}

Hover error says this:

no suitable method found for read(String)
    method ImageIO.read(ImageInputStream) is not applicable
      (actual argument String cannot be converted to ImageInputStream by method invocation conversion)
    method ImageIO.read(URL) is not applicable
      (actual argument String cannot be converted to URL by method invocation conversion)
    method ImageIO.read(InputStream) is not applicable
      (actual argument String cannot be converted to InputStream by method invocation conversion)
    method ImageIO.read(File) is not applicable
      (actual argument String cannot be converted to File by method invocation conversion)

Upvotes: 0

Views: 968

Answers (1)

exexzian
exexzian

Reputation: 7890

problem is with this particular code:
ImageIO.read(Fname);
coz Fname is an String and checking API for read method it doesnt take String as argument in any of its overloaded methods

this reference might help you

Upvotes: 2

Related Questions