ecology_maven/customization/test/ActionTest.java

97 lines
2.7 KiB
Java
Raw Normal View History

2021-11-14 15:29:16 +08:00
package customization.test;
import org.junit.Test;
import aiyh.utils.fileUtil.WatermarkPoint;
import aiyh.utils.fileUtil.WatermarkPointEnum;
import weaver.file.FileUpload;
import weaver.soa.workflow.request.RequestInfo;
import weaver.system.SystemComInfo;
import weaver.workflow.request.RequestManager;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
/**
* @author EBU7-dev1-ayh
* @create 2021/9/7 0007 18:43
* Action test
*/
public class ActionTest extends BaseTest {
@Test
public void testConfig(){
// AddWatermarkAction addWatermarkAction = new AddWatermarkAction();
// RequestInfo requestInfo = new RequestInfo();
// RequestManager requestManager = new RequestManager();
// requestManager.setBilltablename("formtable_main_32");
// requestInfo.setRequestManager(requestManager);
// requestInfo.setWorkflowid("6");
// addWatermarkAction.execute(requestInfo);
}
@Test
public void testPath(){
System.out.println(-170 % 90);
// System.out.println(Math.toRadians(0));
// System.out.println(new WatermarkPoint(WatermarkPointEnum.CENTER));
// System.out.println(FileUpload.getCreateDir(new SystemComInfo().getFilesystem()));
}
@Test
public void createWaterMarkByText() {
File srcImgFile = new File("C:\\Users\\77449\\Desktop\\test.jpg");
String logoText = "[ 天使的翅膀 ]";
File outputImageFile = new File("C:\\Users\\77449\\Desktop\\test_mark.jpg");
double degree = -45;
OutputStream os = null;
try {
Image srcImg = ImageIO.read(srcImgFile);
BufferedImage buffImg = new BufferedImage(srcImg.getWidth(null),
srcImg.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = buffImg.createGraphics();
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics.drawImage(srcImg.getScaledInstance(srcImg.getWidth(null),
srcImg.getHeight(null), Image.SCALE_SMOOTH), 0, 0, null);
graphics.rotate(Math.toRadians(degree),
(double) buffImg.getWidth() / 2,
(double) buffImg.getHeight() / 2);
graphics.setColor(Color.RED);
graphics.setFont(new Font("宋体", Font.BOLD, 36));
float alpha = 0.5f;
graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP,
alpha));
graphics.drawString(logoText, buffImg.getWidth()/3, buffImg.getHeight()/2);
graphics.dispose();
os = new FileOutputStream(outputImageFile);
// 生成图片
ImageIO.write(buffImg, "JPG", os);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != os) {
os.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}