---
title: "tif转换成jpg格式 "
author: "AutomaticThoughts"
date: "2012-09-05T11:17:45Z"
tags: []
categories: ["企业架构"]
slug: "tif-jpg"
draft: false
lastmod: "2012-09-05T11:17:45Z"
id: 1671704
url: "https://automaticthoughts.iteye.com/blog/1671704"
---

public String tifTransfertoJpg(String filePath,String fileName) throws IOException{

/* tif转换到jpg格式 \*/

String input = filePath+fileName;

String output = filePath+fileName.substring(0, StringUtils.lastIndexOf(fileName, "."))+".jpg";

RenderedOp src = JAI.create("fileload", input);

OutputStream os = null;

os = new FileOutputStream(output);

JPEGEncodeParam param = new JPEGEncodeParam();

// 指定格式类型，jpg 属于 JPEG 类型

ImageEncoder enc = ImageCodec.createImageEncoder("JPEG", os, param);

enc.encode(src);

os.close();

return "ftp/"+fileName.substring(0, StringUtils.indexOf(fileName, "."))+".jpg";

}