I want to change jpeg image density from 96 to 100 dpi and bit depth should be 8 bit.
I'm using below code.
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
JPEGImageEncoder jpegEncoder = JPEGCodec.createJPEGEncoder(os1);
JPEGEncodeParam jpegEncodeParam = jpegEncoder.getDefaultJPEGEncodeParam(bufferedImage);
jpegEncodeParam.setDensityUnit(JPEGEncodeParam.DENSITY_UNIT_DOTS_INCH);
jpegEncoder.setJPEGEncodeParam(jpegEncodeParam);
jpegEncodeParam.setQuality(0.40f, true);
jpegEncodeParam.setXDensity(100);
jpegEncodeParam.setYDensity(100);
jpegEncoder.encode(bufferedImage, jpegEncodeParam);
bufferedImage.flush();
It's working fine but in this code Java API showing warning message that is Access restriction: The type 'JPEGImageEncoder' is not API (restriction on required library ...).
and Maven build also by this.
Also tried ImageIO library but It only helps in bit depth and not able to change dpi.