導航:首頁 > 編程語言 > java給圖片加水印

java給圖片加水印

發布時間:2022-03-15 10:21:33

『壹』 用java語言給圖片加水印失敗 在圖片上加一行文字就行! 我添加後圖片象有曝光一樣,發代碼前請自己測試通過

ImageIO.read()讀取圖片是產生的ICC信息的丟失
http://www.oschina.net/question/1092_23668

『貳』 java(最好jsp)給圖片加水印

Java給圖片加水印
/**
* 方法描述:<b>給圖片增加水印.</b></br>
* 備 注: 在圖片上寫字元串
* 創 建 人: bo.gaobo</br>
* 創建日期: 2012-09-07</br>
* @param originalUrl 原始圖片存儲路徑
* @param oldImg 原圖片
* @param str 增加的字元串
* @param xLocation x坐標
* @param yLocation y坐標
* @param fontColor 顏色
* @param fontSize 字型大小
* @param typeFace 字體
* @param fileType 文件類型
*/
public static BufferedImage addStringToImg(String originalUrl, BufferedImage oldImg,String str,int xLocation,int yLocation, Color fontColor, int fontSize, String typeFace, String fileType) throws IOException{
FileOutputStream output = new FileOutputStream(originalUrl);
BufferedImage buffImg = oldImg;
Graphics2D g = buffImg.createGraphics();
g = buffImg.createGraphics();
g.drawImage(buffImg, null, 0, 0);
g.setColor(fontColor); //設置字體顏色
g.setFont(new Font(typeFace, Font.PLAIN, fontSize)); //設置字體和字型大小
g.drawString(str, xLocation, yLocation); //把字元串放在對應的坐標處
g.dispose();
ImageIO.write(buffImg, fileType, output); //設置文件類型
output.close();
return buffImg;
}

『叄』 java 照片加水印 技術有哪些

首先。涉及到文件就要用到文件操作,但我們這是操作圖片
1、我們首先需要一個容器來存放圖片ps:圖片原來在磁碟(File)—-》內存(image)
2、我們要在原來的圖片上加水印,就相當於要在紙上畫畫。。。所以我們的畫紙應該是原圖的一的副本,我們我們需要得到副本並用容器容乃他,
3、畫畫需要畫筆對吧,我們要得到畫副本的筆,當然比肯定有粗細。。。參數設置。。
4、如果就開始畫了。。。首先的找位置。。。我們的圖片就像桌面是二維圖形,就用起始坐標,還是按部就班就從(0,0)開始呢

5、然後萬一我們想歇著畫了呢,java有旋轉畫布的方法
6、開始畫畫了。。。。給定位置。。。給定內容。。下筆了。。。
7、花完了。。是不是就要收拾現場了。。。。收拾好筆,將內存的image輸出到磁碟文件。。。。
上代碼

『肆』 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格式的,你可以試試。

『伍』 Java中給圖片添加水印圖片,怎麼讓水印圖片透明度為百分之50

http://hi..com/hardneedl/blog/item/cbd99b0e4d5f12ec37d122c1.html

『陸』 用java給圖片加水印的問題

很明顯是你自己在圖片加水印時沒有任何限制的加水印

一般情況下,加一次,然後記住本次操作,用資料庫或者什麼其他的,下次訪問該圖片時,就不要再加了。

你給它穿了n多的衣服它不變色才怪

『柒』 java中怎麼樣將水印加在圖片的上面或者下面

去我的博客,java加水印完全示範

http://hi..com/paladian1/blog/item/a243b30ea5ec95236059f354.html

『捌』 java圖片加水印代碼 最好有實例!!!先謝了!!

文字水印
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.swing.*;
import com.sun.image.codec.jpeg.*;

public class WaterSet {
/**
* 給圖片添加水印
*
* @param filePath
* 需要添加水印的圖片的路徑
* @param markContent
* 水印的文字
* @param markContentColor
* 水印文字的顏色
* @param qualNum
* 圖片質量
* @return
*/
public boolean createMark(String filePath, String markContent,
Color markContentColor, float qualNum) {
ImageIcon imgIcon = new ImageIcon(filePath);
Image theImg = imgIcon.getImage();
int width = theImg.getWidth(null);
int height = theImg.getHeight(null);
BufferedImage bimage = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
Graphics2D g = bimage.createGraphics();
g.setColor(markContentColor);
g.setBackground(Color.white);
g.drawImage(theImg, 0, 0, null);
g.drawString(markContent, width / 5, height / 5); // 添加水印的文字和設置水印文字出現的內容
g.dispose();
try {
FileOutputStream out = new FileOutputStream(filePath);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bimage);
param.setQuality(qualNum, true);
encoder.encode(bimage, param);
out.close();
} catch (Exception e) {
return false;
}
return true;
}
}

圖片水印

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import javax.imageio.ImageIO;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;

public final class ImageUtils {
public ImageUtils() {

}

/*
* public final static String getPressImgPath() { return ApplicationContext
* .getRealPath("/template/data/util/shuiyin.gif"); }
*/

/**
* 把圖片印刷到圖片上
*
* @param pressImg --
* 水印文件
* @param targetImg --
* 目標文件
* @param x
* --x坐標
* @param y
* --y坐標
*/
public final static void pressImage(String pressImg, String targetImg,
int x, int y) {
try {
//目標文件
File _file = new File(targetImg);
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);

//水印文件
File _filebiao = new File(pressImg);
Image src_biao = ImageIO.read(_filebiao);
int wideth_biao = src_biao.getWidth(null);
int height_biao = src_biao.getHeight(null);
g.drawImage(src_biao, (wideth - wideth_biao) / 2,
(height - height_biao) / 2, wideth_biao, height_biao, null);
//水印文件結束
g.dispose();
FileOutputStream out = new FileOutputStream(targetImg);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* 列印文字水印圖片
*
* @param pressText
* --文字
* @param targetImg --
* 目標圖片
* @param fontName --
* 字體名
* @param fontStyle --
* 字體樣式
* @param color --
* 字體顏色
* @param fontSize --
* 字體大小
* @param x --
* 偏移量
* @param y
*/

public static void pressText(String pressText, String targetImg,
String fontName, int fontStyle, int color, int fontSize, int x,
int y) {
try {
File _file = new File(targetImg);
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="www.qhd.com.cn";
g.setColor(Color.RED);
g.setFont(new Font(fontName, fontStyle, fontSize));

g.drawString(pressText, wideth - fontSize - x, height - fontSize
/ 2 - y);
g.dispose();
FileOutputStream out = new FileOutputStream(targetImg);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.close();
} catch (Exception e) {
System.out.println(e);
}
}

public static void main(String[] args) {
pressImage("F:/logo.png", "F:/123.jpg", 0, 0);
}
}

『玖』 java實現在同一張圖片上面繪制多個不同位置的水印

Graphics2D g = buffImg.createGraphics();
// 3、設置對線段的鋸齒狀邊緣處理
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawImage(
srcImg.getScaledInstance(srcImg.getWidth(null),
srcImg.getHeight(null), Image.SCALE_SMOOTH), 0, 0, null);
// 5、設置水印文字顏色
g.setColor(color);
// 6、設置水印文字Font
g.setFont(font);
// 7、設置水印文字透明度
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP,
alpha));
// 8、第一參數->設置的內容,後面兩個參數->文字在圖片上的坐標位置(x,y)
g.drawString(logoText, positionX, PositionY);
// 9、釋放資源
g.dispose();,

你這里每一次都重新繪制了圖片,把之前繪制的部分覆蓋了

『拾』 java 給圖片加文字水印

java給圖片加水印,在網上有很多資料,但我想要一個能自適應圖片大小,將水印加在圖片中間或右下角,這個問題我覺得應該是一個演算法的問題
得根據圖片大小調整水印文字的字體大小,及顯示縮進比例,誰有現成的麻煩分享一份,如果不方便在這里說,可以發到我郵箱:
別人都想去掉水印,題主你怎麼還想加水印?

閱讀全文

與java給圖片加水印相關的資料

熱點內容
優信二手車解壓後過戶 瀏覽:61
Windows常用c編譯器 瀏覽:778
關於改善國家網路安全的行政命令 瀏覽:833
安卓如何下載網易荒野pc服 瀏覽:654
javainetaddress 瀏覽:104
蘋果4s固件下載完了怎麼解壓 瀏覽:1003
命令zpa 瀏覽:285
python編譯器小程序 瀏覽:944
在app上看視頻怎麼光線調暗 瀏覽:540
可以中文解壓的解壓軟體 瀏覽:593
安卓卸載組件應用怎麼安裝 瀏覽:913
使用面向對象編程的方式 瀏覽:339
程序員項目經理的年終總結範文 瀏覽:929
內衣的加密設計用來幹嘛的 瀏覽:432
淮安數據加密 瀏覽:292
魔高一丈指標源碼 瀏覽:982
松下php研究所 瀏覽:168
c回調java 瀏覽:399
夢幻端游長安地圖互通源碼 瀏覽:745
電腦本地文件如何上傳伺服器 瀏覽:313