各位大哥大姐!大家好!遇到一个问题,请多多指教! 
如何使用JAI去处理JPEG的resolution。 import com.sun.media.jai.codec.JPEGEncodeParam 我需要改变JPEG的resolution,找不到好的方法,在JAI中找,又找不到。 
请各位大侠帮帮小弟!

解决方案 »

  1.   

    改变图片的分辨率啊?这个我就不知道了...
    你在百度搜不到关于你那个类库的API介绍吗...
      

  2.   

    JPEGEncodeParam的API中没有处理Resolution的接口
    其他的方法有不会,所以来求救呀。
    找到一个新的库
    com.sun.image.codec.jpeg.JPEGEncodeParam
    这个可以处理Resolution,但是当>=300dpi时,就无法处理了。
    代码如下:
                OutputStream oss = new FileOutputStream(inputFilePath);
                JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(oss);
                JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(img);
                param.setQuality(this.imageDensity, true);
                if (this.resolution >= 300) {
                    param.setXDensity(200);
                    param.setYDensity(200);
                } else {
                    param.setXDensity(this.resolution);
                    param.setYDensity(this.resolution);
                }
                param.setDensityUnit(JPEGDecodeParam.DENSITY_UNIT_DOTS_INCH);
                encoder.encode(img, param);
                oss.close();
    /////
    在encoder.encode(img, param);是出错。
    报OutOfMemoryError
    请大家帮忙解答呀
      

  3.   

    JPEGEncodeParam的API中没有处理Resolution的接口
    其他的方法有不会,所以来求救呀。
    找到一个新的库
    com.sun.image.codec.jpeg.JPEGEncodeParam
    这个可以处理Resolution,但是当>=300dpi时,就无法处理了。
    代码如下:
                OutputStream oss = new FileOutputStream(inputFilePath);
                JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(oss);
                JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(img);
                param.setQuality(this.imageDensity, true);
                if (this.resolution >= 300) {
                    param.setXDensity(200);
                    param.setYDensity(200);
                } else {
                    param.setXDensity(this.resolution);
                    param.setYDensity(this.resolution);
                }
                param.setDensityUnit(JPEGDecodeParam.DENSITY_UNIT_DOTS_INCH);
                encoder.encode(img, param);
                oss.close();
    /////
    在encoder.encode(img, param);是出错。
    报OutOfMemoryError
    请大家帮忙解答呀