登录

如何用java 添加水印 精华

sariny 技术论坛
import java.awt.*
import java.awt.event.*
import java.io.*
import java.awt.image.*
import org.w3c.dom.*
import com.sun.image.codec.jpeg.*
import javax.imageio.*
/**
author by http:
//www.5a520.cn
*/
public class ImgBean
public void ImgBean(){} 
public void ImgYin(String s,String ImgName)
try
File _file 
= new File(ImgName); 
Image src 
= ImageIO.read(_file); 
int wideth=src.getWidth(null); 
int height=src.getHeight(null); 
BufferedImage image
=new BufferedImage(wideth,height,BufferedImage.TYPE_INT_RGB); 
Graphics g
=image.createGraphics(); 
g.drawImage(src,
0,0,wideth,height,null); 
String s
="我要加的水印 ,来源http://www.bt285.cn BT下载"
g.setColor(Color.RED); 
g.setFont(
new Font("宋体",Font.PLAIN,20)); 
Font aa
=new Font("宋体",Font.PLAIN,20); 

g.drawString(s,wideth
-150,height-10); 
g.dispose(); 
FileOutputStream out
=new FileOutputStream(ImgName); 
JPEGImageEncoder encoder 
= JPEGCodec.createJPEGEncoder(out); 
encoder.encode(image); 
out.close(); 
}
 
catch(Exception e)
System.out.println(e); 
}
 
}
 
}

展开全文
打开APP,一键看同内容文章>
海盗船复仇者RGB PRO 16GB DDR4 3000仅售1000元(包邮) 三星PM981 PCIE NVME仅售399元(包邮)

网友评论

加载更多

相关推荐

最新问答

查看更多问答
反馈