Win a copy of Murach's Python Programming this week in the Jython/Python forum!
    Bookmark Topic Watch Topic
  • New Topic

How to change the DPI of a image  RSS feed

 
Rohit Kumar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Report post to moderator
HI,

How to change the DPI of a image? (And how to check the DPI is chnaged?)

I tried with JPEGImageEncoder, but can't see any effect even if I chnage DPI value.
Please see the bellow method,


public void saveBufferedImageAsJPEG(BufferedImage bi, int dpi, String fileName)
{
FileOutputStream out = null;
try
{
out = new FileOutputStream(fileName+".jpg");
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
param.setQuality(1f, false);
param.setDensityUnit(JPEGEncodeParam.DENSITY_UNIT_DOTS_INCH);
param.setXDensity(dpi);
param.setYDensity(dpi);
encoder.setJPEGEncodeParam(param);
try
{
encoder.encode(bi);
out.close();
}
catch (IOException io)
{
System.out.println(io);
}
}
catch (FileNotFoundException fnf)
{
System.out.println("File Not Found");
}
}

I read that if i change the DPI value, the size of imaage changes,
i.e. if increase DPI value the image's height and width increases.

But I can not see any effect in resultant image here.

Please let me know if anyone has any information on this.

Thnaks.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please UseOneThreadPerQuestion - we'll continue in this thread.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!