jimi下载地址:
http://java.sun.com/products/jimi/
我使用的是jimi1.0但是转换大的tif时会出错,内存溢出.
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
原本195K的tif只有一页,转换成png后大小为1377kb
如需源tif文件的请发邮件到lwl@cgrs.com.cn
各位大哥帮帮忙啊,小弟现在实在是没分....
public static void main(String[] args) throws JimiException, IOException
{
String strfile="F:\\TiffConvert\\963347528002OR.tif";
//String strfile = "f:\\TiffConvert\\705221558.tif";
toPNG(strfile, "f:\\TiffConvert\\0003", 10);
changeDimension("f:\\TiffConvert\\0003.png", "f:\\TiffConvert\\0003_new.png", 0.9);
}
public static void toPNG(String source, String dest, int quality)
{
if (dest == null || dest.trim().equals(""))
dest = source;
if (!dest.toLowerCase().trim().endsWith("png"))
{
dest += ".png";
System.out.println("Overriding to JPG, output file: " + dest);
}
if (quality < 0 || quality > 100 || (quality + "") == null || (quality + "").equals(""))
{
System.out.println("quality must between ’0’ and ’100’");
System.out.println("set to DEFAULT value:’75’");
quality = 75;
}
try
{
JPGOptions options = new JPGOptions();
options.setQuality(quality);
ImageProducer image = Jimi.getImageProducer(source);
//System.out.println();
JimiWriter writer = Jimi.createJimiWriter(dest);
writer.setSource(image);
writer.setOptions(options);
writer.putImage(dest);
} catch (JimiException je)
{
System.err.println("Error: " + je);
}
}
public static void changeDimension(String source, String desc, double ins) throws JimiException, IOException
{
File _file = null;
if (desc == null || desc.trim().equals(""))
{
desc = source;
}
_file = new File(source); // 读入文件
ImageInputStream iis=new FileImageInputStream(_file);
//javax.imageio.ImageIO.setUseCache(true);
//Image src = javax.imageio.ImageIO.read(_file); // 构造Image对象
//BufferedImage src = ImageIO.read(_file); // 构造Image对象
BufferedImage src = ImageIO.read(iis);
double wideth = (double) src.getWidth(null); // 得到源图宽
double height = (double) src.getHeight(null); // 得到源图长
int iWideth = (int) (wideth * ins);
int iHeight = (int) (height * ins);
BufferedImage tag = new BufferedImage(iWideth, iHeight, BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(src, 0, 0, iWideth, iHeight, null); // 绘制缩小后的图
if (!source.trim().equals(desc))
_file.deleteOnExit();
JimiWriter writer = Jimi.createJimiWriter(desc);
writer.setSource(tag);
writer.putImage(desc);
}
2 个解决方案
#1
我用jai做过jpg转tif的,转换成tig后文件变的很大,是不同格式的图片压缩率的问题。
#2
学习~!@
#1
我用jai做过jpg转tif的,转换成tig后文件变的很大,是不同格式的图片压缩率的问题。
#2
学习~!@