package com.ebay.test1;
import java.awt.image.RenderedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;
import javax.media.jai.JAI;
import javax.media.jai.RenderedOp;
import org.junit.Test;
import com.sun.media.jai.codec.ImageCodec;
import com.sun.media.jai.codec.ImageDecoder;
import com.sun.media.jai.codec.ImageEncoder;
import com.sun.media.jai.codec.JPEGEncodeParam;
public class Snippet {
@Test
public void testTif2JPG2(){
try{
String filename = "F:\\Downloads\\CCITT_2.TIF";
String jpegFileName = "F:\\Downloads\\CCITT_2.JPG";
RenderedOp source = JAI.create("fileload", filename);
FileOutputStream stream = null;
stream = new FileOutputStream(jpegFileName );
com.sun.media.jai.codec.JPEGEncodeParam JPEGparam = new
com.sun.media.jai.codec.JPEGEncodeParam();
ImageEncoder encoder =
ImageCodec.createImageEncoder("jpeg",stream,JPEGparam);
encoder.encode(source);
}catch(Exception e){
e.printStackTrace();
}
}
@Test
public void testTif2JPG3(){
try{
String filename = "F:\\Downloads\\CCITT_2.TIF";
String jpegFileName = "F:\\Downloads\\CCITT_2.JPG";
FileOutputStream stream = null;
stream = new FileOutputStream(jpegFileName );
byte[] b = getBytesFromFile(new File(filename));
InputStream bais = new ByteArrayInputStream(b);
ImageDecoder decoder = ImageCodec.createImageDecoder("tiff", bais, null);
RenderedImage ri = decoder.decodeAsRenderedImage();
// RenderedOp source = JAI.create("TIFF", bais);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JPEGEncodeParam JPEGparam = new JPEGEncodeParam();
JPEGparam.setQuality(Float.MIN_VALUE);
ImageEncoder encoder = ImageCodec.createImageEncoder("jpeg",baos,JPEGparam);
encoder.encode(ri);
byte[] byteArray = baos.toByteArray();
FileOutputStream fos = new FileOutputStream(new File(jpegFileName));
fos.write(byteArray);
}catch(Exception e){
e.printStackTrace();
}
}
@Test
public void testTif2JPG4(){
try{
String filename = "F:\\Downloads\\CCITT_2.TIF";
String jpegFileName = "F:\\Downloads\\CCITT_2.JPG";
FileOutputStream stream = null;
stream = new FileOutputStream(jpegFileName );
byte[] b = getBytesFromFile(new File(filename));
InputStream bais = new ByteArrayInputStream(b);
ImageDecoder decoder = ImageCodec.createImageDecoder("tiff", bais, null);
RenderedImage ri = decoder.decodeAsRenderedImage();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ImageIO.write(ri, "JPEG", outputStream);
stream.write(outputStream.toByteArray());
}catch(Exception e){
e.printStackTrace();
}
}
// Returns the contents of the file in a byte array.
public static byte[] getBytesFromFile(File file) throws IOException {
InputStream is = new FileInputStream(file);
// Get the size of the file
long length = file.length();
// You cannot create an array using a long type.
// It needs to be an int type.
// Before converting to an int type, check
// to ensure that file is not larger than Integer.MAX_VALUE.
if (length > Integer.MAX_VALUE) {
throw new IllegalArgumentException("File is too big, can't support.");
}
// Create the byte array to hold the data
byte[] bytes = new byte[(int)length];
// Read in the bytes
int offset = 0;
int numRead = 0;
while (offset < bytes.length
&& (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
offset += numRead;
}
// Ensure all the bytes have been read in
if (offset < bytes.length) {
throw new IOException("Could not completely read file "+file.getName());
}
// Close the input stream and return bytes
is.close();
return bytes;
}
}
相关推荐
正版jar-codec包名:com.sun.media.jai.codec 、 jai-core包名: javax.media.jai 压缩包附带简单运行demo以及tif图片一张
java操作tif文件切割jpg格式所需要用到的jar。该压缩包内含jai-imageio-core-1.4.0.jar。 tif源自kfb转换而来。 如你的代码业务也同样是kfb转jpg,请移步:...
java操作tif文件转换jpg格式所需要用到的jar。该压缩包内含jai_codec-1.1.3.jar和jai_core-1.1.3.jar。 tif源自kfb转换而来。 如你的代码业务也同样是kfb转jpg,请移步:...
多页tif生成多个单页jpg图片的byte[],然后转为多个具体图片,内容包含工具类及测试类Demo,jai_core-1.1.3.jar,jai-codec-1.1.3.jar。
把JPG、PNG、BMP等格式的图片转为TIF格式文件的依赖包
tiff 转换 jpg jai_codec-1.1.3.jar jai_core-1.1.3.jar
java tif转换包等jar jai-codec-1.1.3 jai_core-1.1.3 java tif转换包等jar ...jai_core-1.1.3java tif转换包等jar jai-codec-1.1.3 jai_core-1.1.3java tif转换包等jar jai-codec-1.1.3 jai_core-1.1.3 很难下
javax.media-jai_codec-1.1.3.jar 和 javax.media-jai_core-1.1.3.jar 将tif图片转换为jpeg图片。修复 java.lang.NoClassDefFoundError: com/sun/image/codec/jpeg/JPEGCodec ,由于这个类已经过时,在新版的OpenJDK...
JAI核心包,图像处理技术,JAI 图片处理JAR包。将tif转为jpg必须的包。maven无法直接下载到。
tif、tiff转jpg,转pdf。无旧压缩格式JPEG解析问题Decoding of old style JPEG-in-TIFF data is not supported。内含所需itextpdf-5.5.5.jar 以及jai-imageio-core-1.4.0.jar
java依赖jai-imageio,非常方便地实现jpg图片转为raw格式图片,raw格式图片转为jpg图片
3个jar包: jai_core-1.1.3.jar jai_imageio.jar jai-codec-1.1.3.jar
java的jar包 jai 图片处理 jai_codec.jar、jai_core.jar、mlibwrapper_jai.jar
jai_codec-1.1.3.jar jai_core.jar jai_imageio.jar jimi-1.0.jar
tiff图片转JPG文件所需jar包,jai_codec-1.1.3.jar 和 jai_core.jar 核心包 亲测可用!
jai的jar包,自己备份,方便大家下载,压缩包内包含了 jai-core-1.1.3.jar jai-lib-1.1.4-b07.jar jai_imageio-1.2-pre-dr-b04.jar
javax.media.jai;javax.media.jai.RenderedOp;
用于tif或是tiff转成jpg,png类型文件
JAI的windows安装包及其相关的jar包(jai_core.jar、jai_codec.jar等)
jai是丰富的图形处理类工具,用来可以方便用来识别bmp。jpg等格式图片内容