導航:首頁 > 編程語言 > javatif轉jpg

javatif轉jpg

發布時間:2024-10-18 13:55:27

java實現多個tif文件圖片拼接

publicstaticvoidmany2one(List<String>bookFilePaths,StringtoPath,StringdistFileName){
if(bookFilePaths!=null&&bookFilePaths.size()>0){
File[]files=newFile[bookFilePaths.size()];
for(inti=0;i<bookFilePaths.size();i++){
files[i]=newFile(bookFilePaths.get(i));
}
if(files!=null&&files.length>0){

try{
ArrayListpages=newArrayList(files.length-1);
FileSeekableStream[]stream=newFileSeekableStream[files.length];
for(inti=0;i<files.length;i++){
stream[i]=newFileSeekableStream(
files[i].getCanonicalPath());
}
ParameterBlockpb=(newParameterBlock());
PlanarImagefirstPage=JAI.create("stream",stream[0]);
for(inti=1;i<files.length;i++){
PlanarImagepage=JAI.create("stream",stream[i]);
pages.add(page);

}
TIFFEncodeParamparam=newTIFFEncodeParam();
Filef=newFile(toPath);
if(!f.exists()){
f.mkdirs();
}
OutputStreamos=newFileOutputStream(toPath+File.separator+distFileName);
ImageEncoderenc=ImageCodec.createImageEncoder("tiff",
os,param);
param.setExtraImages(pages.iterator());
enc.encode(firstPage);
for(inti=0;i<files.length;i++){
stream[i].close();
if(files[i].isFile()&&files[i].exists()){
files[i].delete();
}
}
os.close();
}catch(IOExceptione){
e.printStackTrace();
}
}
}
}

㈡ java 實現 tif圖片(多頁的)轉換成jpg

多頁單個tif文件轉換為多個jpg文件
需要官方的一些包支持(具體參考源碼),上網找找即可。
源碼:
-------------------------
import java.io.*;
import com.sun.media.jai.codec.FileSeekableStream;
import com.sun.media.jai.codec.ImageDecoder;
import com.sun.media.jai.codec.ImageCodec;
import com.sun.media.jai.codec.TIFFEncodeParam;
import com.sun.media.jai.codec.TIFFDecodeParam;
import com.sun.media.jai.codec.JPEGEncodeParam;

import java.awt.image.RenderedImage;
import javax.media.jai.RenderedOp;
import javax.media.jai.JAI;
import java.awt.image.renderable.ParameterBlock;
public class MultiPageRead {
public static void main(String[] args) throws IOException {
new MultiPageRead().doitJAI();
}

public void doitJAI() throws IOException {
FileSeekableStream ss = new FileSeekableStream("./zhaoming.tif");
TIFFDecodeParam param0 = null;
TIFFEncodeParam param = new TIFFEncodeParam();
JPEGEncodeParam param1 = new JPEGEncodeParam();
ImageDecoder dec = ImageCodec.createImageDecoder("tiff", ss, param0);
int count = dec.getNumPages();
param.setCompression(TIFFEncodeParam.COMPRESSION_GROUP4);
param.setLittleEndian(false); // Intel
System.out.println("This TIF has " + count + " image(s)");
for (int i = 0; i < count; i++) {
RenderedImage page = dec.decodeAsRenderedImage(i);
File f = new File("./fk_" + i + ".jpg");
System.out.println("Saving " + f.getCanonicalPath());
ParameterBlock pb = new ParameterBlock();
pb.addSource(page);
pb.add(f.toString());
pb.add("JPEG");
pb.add(param1);
//JAI.create("filestore",pb);
RenderedOp r = JAI.create("filestore",pb);
r.dispose();

//RenderedOp op = JAI.create("filestore", page, "./zhaoming_" + i + ".jpg", "JPEG", param1);
}
}
}

㈢ 怎麼實現用java 把tif格式的圖片轉換成jpg

用photoshop打開,另存為jpg格式就可以了。注意很多tif圖片都是cmyk四色的(印刷格式),如果想把圖片應用於網路上,要轉換成rgb三色的。方法就是打開後,點擊圖像—〉模式—〉rgb顏色。

㈣ Java如何把一個PDF轉為tif

安裝Office時,默認安裝Microsoft Office Document Image Writer組件(沒有重新添加),在Word中,選文件——列印——列印機選「Microsoft Office Document Image Writer」——屬性——高級——輸入格式選「TIFF-黑白傳真」——設置默認輸入的文件夾——確定——確定,列印完成後,將輸出到剛設置的默認文件夾中。

㈤ 高分求java代碼,用來生成圖片文件!!

//defaultSuffix是jpg
public static final boolean resizeImage(String fileName, String suffix) throws Exception {
boolean uploaded = false;
BufferedImage input;
if(suffix.equalsIgnoreCase("tif")||suffix.equalsIgnoreCase("tiff")||suffix.equalsIgnoreCase("png")) {
RenderedImage image = JAI.create("fileload", TurbineServlet.getRealPath(imageRoot + fileName+"."+suffix));
WritableRaster raster = image.Data(null);
BufferedImage bi = new BufferedImage( image.getColorModel(), raster, true, null);
BufferedImage bi2 = new BufferedImage( maxResizeDimension, bi.getHeight()*maxResizeDimension/bi.getWidth(), BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = bi2.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2.setBackground(java.awt.Color.WHITE);//把tiff和png轉換後的背景設置為白色
g2.fillRect(0, 0, maxResizeDimension, bi.getHeight()*maxResizeDimension/bi.getWidth());
g2.drawImage(bi, 0, 0, maxResizeDimension, bi.getHeight()*maxResizeDimension/bi.getWidth(), null);
PlanarImage pi = PlanarImage.wrapRenderedImage(bi2);
JAI.create("FileStore", pi, TurbineServlet.getRealPath(resizeRoot + fileName+"."+defaultSuffix).replaceAll("\\\\","\\\\\\\\"), "JPEG", new JPEGEncodeParam());
input = pi.getAsBufferedImage();
int w = maxThumbDimension, h = maxThumbDimension;

BufferedImage output = new BufferedImage(w, h, BufferedImage.TYPE_3BYTE_BGR);
Graphics2D g = output.createGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawImage(input,0,0,w,h, null);
ImageIO.write(output, defaultSuffix, new File(TurbineServlet.getRealPath(thumbRoot + fileName+"."+defaultSuffix)));
}
else {
input = ImageIO.read(new File(TurbineServlet.getRealPath(imageRoot + fileName+"."+suffix)));
int w = maxThumbDimension, h = maxThumbDimension;

BufferedImage output = new BufferedImage(w, h, BufferedImage.TYPE_3BYTE_BGR);
Graphics2D g = output.createGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawImage(input,0,0,w,h, null);
ImageIO.write(output, defaultSuffix, new File(TurbineServlet.getRealPath(thumbRoot + fileName+"."+defaultSuffix)));

BufferedImage output2 = new BufferedImage(maxResizeDimension, input.getHeight()*maxResizeDimension/input.getWidth(), BufferedImage.TYPE_3BYTE_BGR);
Graphics2D g2 = output2.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2.drawImage(input,0,0,maxResizeDimension, input.getHeight()*maxResizeDimension/input.getWidth(), null);
ImageIO.write(output2, defaultSuffix, new File(TurbineServlet.getRealPath(resizeRoot + fileName+"."+defaultSuffix)));
}
uploaded = true;
return uploaded;
}

㈥ java給tif格式圖片加文字水印

packagecom.coderli.image;
importjava.awt.Color;
importjava.awt.Font;
importjava.awt.Graphics;
importjava.awt.Image;
importjava.awt.image.BufferedImage;
importjava.io.File;
importjava.io.FileOutputStream;

importjavax.imageio.ImageIO;

importcom.sun.image.codec.jpeg.JPEGCodec;
importcom.sun.image.codec.jpeg.JPEGImageEncoder;

@SuppressWarnings("restriction")
publicfinalclassImageUtils{
publicImageUtils(){

}


/**
*列印文字水印圖片
*
*@parampressText
*--文字
*@paramtargetImg--
*目標圖片
*@paramfontName--
*字體名
*@paramfontStyle--
*字體樣式
*@paramcolor--
*字體顏色
*@paramfontSize--
*字體大小
*@paramx--
*偏移量
*@paramy
*/

publicstaticvoidpressText(StringpressText,StringtargetImg,
StringfontName,intfontStyle,Colorcolor,intfontSize,intx,
inty){
try{
File_file=newFile(targetImg);
Imagesrc=ImageIO.read(_file);
intwidth=src.getWidth(null);
intheight=src.getHeight(null);
BufferedImageimage=newBufferedImage(width,height,
BufferedImage.TYPE_INT_RGB);
Graphicsg=image.createGraphics();
g.drawImage(src,0,0,width,height,null);
g.setColor(color);
g.setFont(newFont(fontName,fontStyle,fontSize));

g.drawString(pressText,width-fontSize-x,height-fontSize
/2-y);
g.dispose();
FileOutputStreamout=newFileOutputStream(targetImg);
JPEGImageEncoderencoder=JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.close();
}catch(Exceptione){
System.out.println(e);
}
}

publicstaticvoidmain(String[]args){
pressText("bbs.coderli.com","f:/1.tiff","TimesNewRomas",Font.PLAIN,Color.BLUE,22,150,20);
}
}

這個方法里用的api是支持tiff格式的,你可以試試。

閱讀全文

與javatif轉jpg相關的資料

熱點內容
pdf膜官網 瀏覽:598
游戲資源文件存在哪個文件夾 瀏覽:6
mc怎麼用命令方塊無限生成僵屍 瀏覽:793
英文蝦皮app怎麼登錄 瀏覽:432
同花順app怎麼確定盤中個股買入點 瀏覽:867
程序員摸底考試考什麼 瀏覽:525
如果編譯器是中文 瀏覽:515
程序員升職怎麼談 瀏覽:109
android機頂盒ui 瀏覽:359
tb編譯器 瀏覽:728
怎麼壓縮圖片和視頻在一起 瀏覽:563
gcc編譯win 瀏覽:229
單片機定時器t1初值怎麼算 瀏覽:642
android保存聯系人 瀏覽:196
菜雞app里的聯機游戲怎麼聯機 瀏覽:265
文件伺服器怎麼做許可權控制 瀏覽:954
壓縮機電機軸承 瀏覽:975
lol台服對戰伺服器延遲高怎麼辦 瀏覽:303
java路徑斜杠 瀏覽:383
java問號泛型 瀏覽:152