這篇文章主要講解了“java畫圖工具來添加水印的實(shí)現(xiàn)方法”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“java畫圖工具來添加水印的實(shí)現(xiàn)方法”吧!

在薩嘎等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站制作、成都網(wǎng)站設(shè)計 網(wǎng)站設(shè)計制作按需定制,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站設(shè)計,成都全網(wǎng)營銷推廣,外貿(mào)網(wǎng)站建設(shè),薩嘎網(wǎng)站建設(shè)費(fèi)用合理。
不多嗶嗶,直接上代碼:
/**
* @param srcImgFile 原圖片文件對象
* @param outFile 輸出圖片文件對象
* @param waterMarkContent 水印內(nèi)容
* @param markContentColor 水印顏色
* @param rate 字體間距
* @param x x軸位置
* @param y y軸位置
* @param font 字體
*/
public static void addWaterMark(File srcImgFile, File outFile, String waterMarkContent, Color markContentColor, double rate, int x, int y, Font font) {
try {
// 讀取原圖片信息
Image srcImg = ImageIO.read(srcImgFile);//文件轉(zhuǎn)化為圖片
int srcImgWidth = srcImg.getWidth(null);//獲取圖片的寬
int srcImgHeight = srcImg.getHeight(null);//獲取圖片的高
// 加水印
BufferedImage bufImg = new BufferedImage(srcImgWidth, srcImgHeight, BufferedImage.TYPE_INT_RGB); // 獲取圖片緩沖區(qū)
Graphics2D g = bufImg.createGraphics(); // 創(chuàng)建Graphics2D畫筆對象
g.drawImage(srcImg, 0, 0, srcImgWidth, srcImgHeight, null);
g.setColor(markContentColor); //根據(jù)圖片的背景設(shè)置水印顏色
g.setFont(font); //設(shè)置字體
WaterMarkUtils.MyDrawString(waterMarkContent,x,y,rate,g); // 設(shè)置字體間距加輸出
g.dispose(); // 進(jìn)行處理
// 輸出圖片
FileOutputStream outImgStream = new FileOutputStream(outFile); // 創(chuàng)建文件輸出流
ImageIO.write(bufImg, "jpg", outImgStream);
System.out.println("添加水印完成");
outImgStream.flush(); // 刷新文件
outImgStream.close(); // 釋放資源
} catch (Exception e) {
System.out.println("異常");
e.printStackTrace();
}
}這個是在百度上找的,原貼的地址https://blog.csdn.net/zixiaomuwu/article/details/51068698
/**
* 設(shè)置字體間距加輸出
* @param str 輸出字符串
* @param x x軸
* @param y y軸
* @param rate 字體間距
* @param g 畫筆對象
*/
public static void MyDrawString(String str,int x,int y,double rate,Graphics2D g){
String tempStr=new String();
int orgStringWight=g.getFontMetrics().stringWidth(str);
int orgStringLength=str.length();
int tempx=x;
int tempy=y;
while(str.length()>0)
{
tempStr=str.substring(0, 1);
str=str.substring(1, str.length());
g.drawString(tempStr, tempx, tempy);
tempx=(int)(tempx+(double)orgStringWight/(double)orgStringLength*rate);
}
}感謝各位的閱讀,以上就是“java畫圖工具來添加水印的實(shí)現(xiàn)方法”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對java畫圖工具來添加水印的實(shí)現(xiàn)方法這一問題有了更深刻的體會,具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識點(diǎn)的文章,歡迎關(guān)注!
網(wǎng)站名稱:java畫圖工具來添加水印的實(shí)現(xiàn)方法
文章出自:http://www.chinadenli.net/article30/iieepo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、App設(shè)計、企業(yè)網(wǎng)站制作、用戶體驗(yàn)、ChatGPT、標(biāo)簽優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)