当前位置:网站首页>Image watermarking, scaling and conversion of an input stream
Image watermarking, scaling and conversion of an input stream
2022-07-07 01:42:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack
Watermark and zoom pictures :
public final static BufferedImage[] pressImage(InputStream srcImg, String waterImg,float alpha) throws IOException {
//File file = new File(targetImg);
Image image = ImageIO.read(srcImg);
int width = image.getWidth(null);
int height = image.getHeight(null);
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g = bufferedImage.createGraphics();
g.drawImage(image, 0, 0, width, height, null);
Image waterImage = ImageIO.read(new File(waterImg)); // Watermark file
int width_1 = waterImage.getWidth(null);
int height_1 = waterImage.getHeight(null);
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
int div=(int) (0.1*width_1);
for(int y=0,row=0;y<height;y+=height_1+div,row++)
{
int x=0;
for(;x<width;x+=width_1+div)
{
g.drawImage(waterImage, x, y, width_1, height_1, null); // End of watermark file
}
}
g.dispose();
BufferedImage bufferedImage2=Thumbnails.of(bufferedImage).size(100, 100).asBufferedImage();
return new BufferedImage[]{bufferedImage,bufferedImage2};
}
The zoom of the picture uses Thumbnails This tool ,( In fact, it can also be used to make watermarks , It's just that I haven't studied )
jar Packages or maven Please search by yourself
Special attention should be paid to Thumbnails By default, it is scaled in equal proportion, and its scaling rule is :
If Put the picture in 200*300
* If the horizontal ratio of the picture 200 Small . High ratio 300 Small . unchanged * If the horizontal ratio of the picture 200 Small , High ratio 300 Big . The height is reduced to 300, The scale of the picture is the same * If the horizontal ratio of the picture 200 Big , High ratio 300 Small . Horizontal reduction to 200. The scale of the picture is the same * If the horizontal ratio of the picture 200 Big , High ratio 300 Big . The picture is scaled down , Horizontal 200 Or as high as 300
bufferInage transformation inputSteam
private InputStream getInputstreamFromBufferedImage(BufferedImage img) throws IOException{
ByteArrayOutputStream bs =new ByteArrayOutputStream();
ImageOutputStream imOut =ImageIO.createImageOutputStream(bs);
ImageIO.write(img,"jpg",imOut); //scaledImage1 by BufferedImage,jpg Is the type of image
InputStream is =new ByteArrayInputStream(bs.toByteArray());
return is;
}
Copyright notice : This article is the original article of the blogger , Blog , Do not reprint without permission .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/116890.html Link to the original text :https://javaforall.cn
边栏推荐
- hdu 4661 Message Passing(木DP&amp;组合数学)
- mysqlbackup 还原特定的表
- 糊涂工具类(hutool)post请求设置body参数为json数据
- What does front-end processor mean? What is the main function? What is the difference with fortress machine?
- 从零开始匹配vim(0)——vimscript 简介
- Send template message via wechat official account
- 场景实践:基于函数计算快速搭建Wordpress博客系统
- THREE. AxesHelper is not a constructor
- 域分析工具BloodHound的使用说明
- Gin 入门实战
猜你喜欢
Baidu flying general BMN timing action positioning framework | data preparation and training guide (Part 2)
AI 从代码中自动生成注释文档
JVM 内存模型
Send template message via wechat official account
LeetCode. 剑指offer 62. 圆圈中最后剩下的数
shell脚本快速统计项目代码行数
移植DAC芯片MCP4725驱动到NUC980
Appium自动化测试基础 — uiautomatorviewer定位工具
百度飞将BMN时序动作定位框架 | 数据准备与训练指南 (上)
1123. 最深叶节点的最近公共祖先
随机推荐
域分析工具BloodHound的使用说明
Byte P7 professional level explanation: common tools and test methods for interface testing, Freeman
What does front-end processor mean? What is the main function? What is the difference with fortress machine?
移植DAC芯片MCP4725驱动到NUC980
Add the applet "lazycodeloading": "requiredcomponents" in taro,
爬虫实战(六):爬笔趣阁小说
Right mouse button customization
AcWing 1140. 最短网络 (最小生成树)
Let's see how to realize BP neural network in Matlab toolbox
修改px4飞控的系统时间
Hutool post requests to set the body parameter to JSON data
LeetCode:1175. 质数排列
从零开始匹配vim(0)——vimscript 简介
Telnet,SSH1,SSH2,Telnet/SSL,Rlogin,Serial,TAPI,RAW
图片打水印 缩放 和一个输入流的转换
JS ES5也可以创建常量?
Appium基础 — Appium Inspector定位工具(一)
7.6模拟赛总结
Today's question -2022/7/4 modify string reference type variables in lambda body
WCF基金会