i want to get the buffered image format or type of image using java,
InputStream stream = request.getResponseStream();
BufferedImage image= ImageIO.read(stream);
LOGGER.info(image);
i want to get the buffered image format or type of image using java,
InputStream stream = request.getResponseStream();
BufferedImage image= ImageIO.read(stream);
LOGGER.info(image);
Refer the javax.imageio.ImageIO.read()
code
This code originally implemented in groovy but translated into java so It may have a syntax error.
public String read(InputStream input) throws IOException {
ImageInputStream stream = ImageIO.createImageInputStream(input);
Iterator iter = ImageIO.getImageReaders(stream);
if (!iter.hasNext()) {
return null;
}
ImageReader reader = (ImageReader) iter.next();
ImageReadParam param = reader.getDefaultReadParam();
reader.setInput(stream, true, true);
BufferedImage bi;
try {
bi = reader.read(0, param);
return reader.getFormatName();
} finally {
reader.dispose();
stream.close();
}
}
This code might help you to get the extension of image
public static String getFormate(String ImageName) {
return (ImageName.substring(ImageName.indexOf('.'),ImageName.length()));
}
In the above code first it searches dot(.) and with help of substring() it will return the extension
ImageName
from InputStream
was provided. Practically there is no solution –
Hydrology © 2022 - 2024 — McMap. All rights reserved.