中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁(yè) > news >正文

怎么對(duì)網(wǎng)站做壓力測(cè)試seo排名優(yōu)化價(jià)格

怎么對(duì)網(wǎng)站做壓力測(cè)試,seo排名優(yōu)化價(jià)格,網(wǎng)站制作中搜索欄怎么做,網(wǎng)站提現(xiàn)功能開(kāi)發(fā)今天干了一件特別不務(wù)正業(yè)的事,做了一個(gè)小程序用來(lái)給圖片添加水印。事情的起因是需要將自己的身份證照片分享給別人,手邊并沒(méi)有一個(gè)趁手的工具來(lái)生成圖片水印。很多APP提供了水印的功能,但會(huì)把我的圖片上傳到他們的服務(wù)器,身份證太…

今天干了一件特別不務(wù)正業(yè)的事,做了一個(gè)小程序用來(lái)給圖片添加水印。事情的起因是需要將自己的身份證照片分享給別人,手邊并沒(méi)有一個(gè)趁手的工具來(lái)生成圖片水印。很多APP提供了水印的功能,但會(huì)把我的圖片上傳到他們的服務(wù)器,身份證太敏感了,顯然我并不想讓別人有機(jī)會(huì)保留照片。

我把圖片處理做了一個(gè)抽象,入?yún)⑹荁ufferedImage,對(duì)圖片添加水印、盲印、隱式寫(xiě)入后返回新的BufferedImage作為結(jié)果。

package org.keyniu.watermark.image;import java.awt.image.BufferedImage;public interface ImageProcess {/*** @param org* @return*/public BufferedImage process(BufferedImage org) throws Exception;}

1. 基本實(shí)現(xiàn)

我們先給出一版基本的實(shí)現(xiàn)

package org.keyniu.watermark.image;...
/*** 基于JDK的Graphics2D實(shí)現(xiàn)*/
public class Graphics2DWatermark implements ImageProcess {...     public BufferedImage process(BufferedImage org) throws UnsupportedEncodingException, NoSuchAlgorithmException {BufferedImage marked = new BufferedImage(org.getWidth(), org.getHeight(), BufferedImage.TYPE_INT_RGB);Graphics2D g2d = marked.createGraphics();g2d.drawImage(org, 0, 0, null); // 創(chuàng)建結(jié)果圖片,并繪制原圖// 設(shè)置字體,計(jì)算每個(gè)水印文字的塊大小FontRenderContext context = g2d.getFontRenderContext();Font font = new Font(fontName, Font.BOLD, fontSize);g2d.setFont(font);TextMetadata textMeta = getTextMetadata(font, context, text);// 設(shè)置水印透明度,默認(rèn)選擇45°g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); // 設(shè)置透明度,0.0~1.0g2d.rotate(Math.PI * rotateArch / 180, org.getWidth() / 2, org.getHeight() / 2);// 計(jì)算圖片中每行能放幾個(gè)水印,要放多少行ImageMetadata imageMeta = new ImageMetadata(org.getWidth(), org.getHeight());int columnCount = imageMeta.getColumnCount(textMeta.getWidth());int rowCount = imageMeta.getRowCount(textMeta.getHeight() + textMeta.getCrcHeight());AffineTransform transform = g2d.getTransform();for (int rIdx = 0; rIdx < rowCount; rIdx++) {for (int cIdx = 0; cIdx < columnCount; cIdx++) {g2d.setTransform(transform);randomRotate(g2d, imageMeta);randomTransform(g2d);watermark(g2d, imageMeta, textMeta, rIdx, cIdx);}}g2d.setTransform(transform);// 結(jié)束繪制,釋放資源g2d.dispose();return marked;}private void watermark(Graphics2D g2d, ImageMetadata imageMeta, TextMetadata textMeta, int rIdx, int cIdx) {Point offset = imageMeta.getOffset();Point textLoc = textMeta.textLocation(rIdx, cIdx);Point crcLoc = textMeta.crcLocation(rIdx, cIdx);randomGradient(g2d, offset.x + textLoc.x, offset.y + textLoc.y, textMeta.totalTextWidth(), textMeta.totalTextHeight());g2d.drawString(textMeta.getText(), offset.x + textLoc.x, offset.y + textLoc.y);randomGradient(g2d, offset.x + crcLoc.x, offset.y + crcLoc.y, textMeta.totalCrcWidth(), textMeta.totalCrcHeight());g2d.drawString(textMeta.getCrc(), offset.x + crcLoc.x, offset.y + crcLoc.y);}protected void randomRotate(Graphics2D g2d, ImageMetadata imageMeta) { // 供子類(lèi)覆蓋,自定義旋轉(zhuǎn)的邏輯}protected void randomTransform(Graphics2D g2d) { // 供子類(lèi)覆蓋,自定義AffineTransform的邏輯}protected void randomGradient(Graphics2D g2d, int x, int y, int dx, int dy) { // 供子類(lèi)覆蓋,實(shí)現(xiàn)漸變色的邏輯}... 
}

本地main方法測(cè)試,測(cè)試代碼是這樣的的。

public static void main(String[] args) throws Exception {Graphics2DWatermark watermark = new Graphics2DWatermark("僅用于車(chē)險(xiǎn)辦理");BufferedImage image = ImageIO.read(new File("D:\\blog\\linux.png"));BufferedImage certified = watermark.process(image);ImageIO.write(certified, "jpg", new File("D:\\blog\\linux_mark.png"));
}

左邊是原始圖片,右邊是加了水印后的圖片

2. 旋轉(zhuǎn)變換

太有規(guī)律的水印很容易就被擦除水印,上面的實(shí)現(xiàn)中我們預(yù)留了3個(gè)接口,用來(lái)擴(kuò)展實(shí)現(xiàn),分別是:

  1. randomRotate,輸出一行水印之前,有機(jī)會(huì)做旋轉(zhuǎn)
  2. randomTransform,輸出一行水印前,有機(jī)會(huì)執(zhí)行AffineTransfrom
  3. randomGradient,輸出水印文字和CRC之前,有機(jī)會(huì)設(shè)置漸變色

我們提供了一個(gè)增強(qiáng)實(shí)現(xiàn)

public class EnhancedGraphics2DWatermark extends Graphics2DWatermark {public EnhancedGraphics2DWatermark(String text) {super(text);}protected void randomRotate(Graphics2D g2d, ImageMetadata imageMeta) {g2d.rotate(Math.PI * (Math.random() * 45 - 45) / 180, imageMeta.getSourceX(), imageMeta.getSourceY());}@Overrideprotected void randomTransform(Graphics2D g2d) {if (Math.random() < 0.5) {g2d.shear(Math.random() * 0.2, 0);} else {g2d.shear(0, Math.random() * 0.2);}}protected void randomGradient(Graphics2D g2d, int fx, int fy, int tx, int ty) {Color from = generateColor();Color to = reverse(from);GradientPaint gp = new GradientPaint(fx, fy, from, tx, ty, to);g2d.setPaint(gp);}private Color generateColor() {int r = (int) (256 * Math.random() + fontColor.getRed()) & 0xFF;int g = (int) (256 * Math.random() + fontColor.getGreen()) & 0xFF;int b = (int) (256 * Math.random() + fontColor.getBlue()) & 0xFF;return new Color(r, g, b);}private Color reverse(Color c) {return new Color((256 - c.getRed()) & 0xFF, (256 - c.getGreen()) & 0xFF, (256 - c.getBlue()) & 0XFF, c.getAlpha());}}

修改測(cè)試的main方法,改用這個(gè)實(shí)現(xiàn)

public static void main(String[] args) throws Exception {Graphics2DWatermark watermark = new EnhancedGraphics2DWatermark("僅用于車(chē)險(xiǎn)辦理");BufferedImage image = ImageIO.read(new File("D:\\blog\\linux.png"));BufferedImage certified = watermark.process(image);ImageIO.write(certified, "jpg", new File("D:\\blog\\linux_mark.png"));
}

這是新的水印效果

3. 提供GUI訪(fǎng)問(wèn)

直接通過(guò)代碼來(lái)調(diào)用對(duì)非程序來(lái)說(shuō)太有友好了,所以我在上一篇的基礎(chǔ)上做了一點(diǎn)點(diǎn)改成,做了一個(gè)GUI入口,通過(guò)菜單設(shè)置水印的文案

然后再使用JFileChooser打開(kāi)一個(gè)圖片文件,最終展示水印后的圖片。

完整的項(xiàng)目代碼見(jiàn)附件,如果使用GraalVM打包稱(chēng)為可執(zhí)行文件,就可以分享給你的小伙伴們使用啦。

http://www.risenshineclean.com/news/9640.html

相關(guān)文章:

  • wordpress靜態(tài)ip上海優(yōu)化外包
  • 合肥政務(wù)新區(qū)建設(shè)局網(wǎng)站百度搜索引擎的功能
  • 莆田有哪幾家做網(wǎng)站設(shè)計(jì)的全球網(wǎng)站排名前100
  • 建筑工程有限責(zé)任公司搜索引擎優(yōu)化教程
  • 公司網(wǎng)站的建站要點(diǎn)seo還有前景嗎
  • 西安網(wǎng)站設(shè)計(jì)品牌詞優(yōu)化
  • 華碩路由器做網(wǎng)站什么軟件可以發(fā)帖子做推廣
  • 做電商有哪些網(wǎng)站推廣平臺(tái)收費(fèi)標(biāo)準(zhǔn)
  • 上海網(wǎng)站改版服務(wù)百度葷seo公司
  • 小米手機(jī)做網(wǎng)站服務(wù)器嗎網(wǎng)站排名優(yōu)化公司
  • 哈爾濱快速建站案例百度識(shí)圖網(wǎng)頁(yè)版入口
  • 彩票網(wǎng)站怎么做的營(yíng)銷(xiāo)模式
  • 凡科做網(wǎng)站不要錢(qián)seo搜索引擎入門(mén)教程
  • 做報(bào)名網(wǎng)站中國(guó)國(guó)家培訓(xùn)網(wǎng)是真的嗎
  • spd2007怎么創(chuàng)建網(wǎng)站品牌推廣的意義
  • 網(wǎng)站開(kāi)發(fā)代理報(bào)價(jià)表成都私人網(wǎng)站制作
  • 北京做網(wǎng)站在線(xiàn)html5制作網(wǎng)站
  • 泰安人力資源招聘長(zhǎng)沙靠譜關(guān)鍵詞優(yōu)化服務(wù)
  • 獨(dú)立設(shè)計(jì)購(gòu)物網(wǎng)站網(wǎng)絡(luò)推廣方案范例
  • 網(wǎng)站seo優(yōu)化關(guān)鍵詞國(guó)內(nèi)外搜索引擎大全
  • 學(xué)校網(wǎng)站設(shè)計(jì)的作用營(yíng)銷(xiāo)平臺(tái)建設(shè)
  • wordpress限制站點(diǎn)使用時(shí)間河南品牌網(wǎng)站建設(shè)
  • 最基本的網(wǎng)絡(luò)營(yíng)銷(xiāo)站點(diǎn)西安優(yōu)化網(wǎng)站公司
  • wordpress做的好的網(wǎng)站如何優(yōu)化網(wǎng)站快速排名
  • 萊山做網(wǎng)站的公司熊貓關(guān)鍵詞工具官網(wǎng)
  • 域名注冊(cè)后怎么建網(wǎng)站全網(wǎng)營(yíng)銷(xiāo)推廣案例
  • 商城網(wǎng)站都有什么功能模塊免費(fèi)網(wǎng)站推廣工具
  • 網(wǎng)站建設(shè)規(guī)劃書(shū)的空間seo軟文代寫(xiě)
  • 做網(wǎng)站學(xué)習(xí)營(yíng)銷(xiāo)策略范文
  • 長(zhǎng)沙企業(yè)網(wǎng)站建設(shè)服務(wù)怎么做網(wǎng)址