日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

9宫格 java_java 拼接头像9宫格

發(fā)布時(shí)間:2024/9/19 编程问答 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 9宫格 java_java 拼接头像9宫格 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

java后臺(tái)拼接9宮格頭像和添加水印文字,效果:

? ? ?

參考:https://blog.csdn.net/shichen88/article/details/101293541

1、拼接工具類:

package com.bai.blog.utils.files;

import javax.imageio.ImageIO;

import java.awt.*;

import java.awt.geom.AffineTransform;

import java.awt.geom.RoundRectangle2D;

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.IOException;

import java.util.ArrayList;

import java.util.List;

/**

* 拼接圖片 參考:https://blog.csdn.net/shichen88/article/details/101293541

* FileName: FileSplitUtil

* Create by: 漠天

* Date: 2019/12/23

*/

public class FileSplitUtil {

/**

* 合成圖片

*

* @param imagePaths List* @param message String

* @param outPutPath String

* @throws IOException

* return String

*/

public static String overlapImage(ListimagePaths, String message, String outPutPath) throws IOException {

int withAndHeight = 530;//背景圖片的寬高

int dividerWithAndHeight = 20;//divider分割空白寬高

int sonImageWithAndHeight = 150;//畫的子頭像圖片的寬高

int sonImageRadius= 30;//畫的子頭像的圓角

// 設(shè)置背景圖片大小,自己添加替換圖片邏輯

// BufferedImage backgroundImage = resizeImage(566, 230, ImageIO.read(new File(backgroundPath)));

//new一個(gè)白色背景板

BufferedImage backgroundImage = new BufferedImage(withAndHeight,withAndHeight,BufferedImage.TYPE_INT_ARGB);

backgroundImage.getGraphics().setColor(Color.white);

backgroundImage.getGraphics().fillRect(0,0,withAndHeight,withAndHeight);

backgroundImage.getGraphics().dispose();

backgroundImage = setClip(backgroundImage,30);

// 初始化有效的圖片BufferedImage列表

ListbufferedImageList = new ArrayList<>();

for(String imagePath:imagePaths){

bufferedImageList.add(setClip(resizeImage(sonImageWithAndHeight, sonImageWithAndHeight, ImageIO.read(new File(imagePath))),sonImageRadius));

}

// 獲取背景畫布

Graphics2D graphics = backgroundImage.createGraphics();

// 在背景圖片上添加文字

graphics.setColor(Color.blue);

graphics.setFont(new Font("宋體", Font.PLAIN, 20));

graphics.drawString(message, sonImageWithAndHeight/3, sonImageWithAndHeight/3);

// 畫出旋轉(zhuǎn)的文字,在指定位置

Font font = new Font("宋體", Font.PLAIN, 80);

AffineTransform affineTransform = new AffineTransform();

affineTransform.rotate(-Math.toRadians(45), 50, 20);

Font rotatedFont = font.deriveFont(affineTransform);

graphics.setFont(rotatedFont);

graphics.drawString(message, sonImageWithAndHeight, withAndHeight-sonImageWithAndHeight);

// 在背景圖片上添加子圖片

if(bufferedImageList.size()>0){

if(bufferedImageList.size()<2){

graphics.drawImage(bufferedImageList.get(0), dividerWithAndHeight, dividerWithAndHeight, withAndHeight-dividerWithAndHeight*2, withAndHeight-dividerWithAndHeight*2, null);

}else if(bufferedImageList.size()<3){

int newSonWidth = withAndHeight/2-dividerWithAndHeight*2;

int centerPlex =(withAndHeight-newSonWidth)/2;

graphics.drawImage(bufferedImageList.get(0), dividerWithAndHeight+dividerWithAndHeight/2, centerPlex, newSonWidth, newSonWidth, null);

graphics.drawImage(bufferedImageList.get(1), newSonWidth+dividerWithAndHeight*2+dividerWithAndHeight/2, centerPlex, newSonWidth, newSonWidth, null);

}else if(bufferedImageList.size()<10){

for(int i=0;i

2、調(diào)用:

ListformatFilePath = new ArrayList<>();

formatFilePath.add("D:/JavaLibFiles/Files/1.png");

formatFilePath.add("D:/JavaLibFiles/Files/2.png");

formatFilePath.add("D:/JavaLibFiles/Files/3.png");

formatFilePath.add("D:/JavaLibFiles/Files/4.png");

formatFilePath.add("D:/JavaLibFiles/Files/5.png");

formatFilePath.add("D:/JavaLibFiles/Files/6.png");

formatFilePath.add("D:/JavaLibFiles/Files/7.png");

String outPutPath = "D:/JavaLibFiles/Files/splitImage.png";

String message = "測(cè)試拼接信息";

String splitResultImagePath = FileSplitUtil.overlapImage(formatFilePath,message,outPutPath);

// 結(jié)果地址:splitResultImagePath

總結(jié)

以上是生活随笔為你收集整理的9宫格 java_java 拼接头像9宫格的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。