Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to change the DPI of a image

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please UseOneThreadPerQuestion - we'll continue in this thread.
    Bookmark Topic Watch Topic
  • New Topic