服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

一个简单的将bmp图片转换成tif

1: go to http://java.sun.com/products/java-media/jai/current.html
download java advanced imaging 1.1.2
2: put the lib in your jdk
3: following is the sample i convert my tif to bmp file:
import java.io.fileoutputstream;
import java.io.outputstream;
import javax.media.jai.jai;
import javax.media.jai.renderedop;
import com.sun.media.jai.codec.bmpencodeparam;
import com.sun.media.jai.codec.imagecodec;
import com.sun.media.jai.codec.imageencoder;
/*
 * created on 2004-8-22
 *
 * todo to change the template for this generated file go to
 * window - preferences - java - code style - code templates
 */
/**
 * @author huang jinxiang
 *
 * todo to change the template for this generated type comment go to
 * window - preferences - java - code style - code templates
 */
public class test {
    public static void main(string[] args) throws exception{
        string inputfile = "me.tif";
        string outputfile = "out.bmp";
        renderedop src = jai.create("fileload", inputfile);
        outputstream os = new fileoutputstream(outputfile);
        bmpencodeparam param = new bmpencodeparam();
        imageencoder enc = imagecodec.createimageencoder("bmp", os,
                                                         param);
        enc.encode(src);
        os.close();
    }
}
 
for more details, you can go & check from :
http://java.sun.com/products/java-media/jai/fordevelopers/jai1_0_1guide-unc/encode.doc.html#47285
 
 
反过来你就可以把bmp转成tif的了...
只不过用不同的codec..
所以可以在bmp, jpg, png, tif之间相互转换....

扫描关注微信公众号