当前位置:网站首页>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
边栏推荐
- JS ES5也可以創建常量?
- tansig和logsig的差异,为什么BP喜欢用tansig
- shell脚本快速统计项目代码行数
- 一文带你走进【内存泄漏】
- 使用nodejs完成判断哪些项目打包+发版
- MySQL最基本的SELECT(查询)语句
- 交叉验证如何防止过拟合
- Machine learning: the difference between random gradient descent (SGD) and gradient descent (GD) and code implementation.
- Google released a security update to fix 0 days that have been used in chrome
- C language instance_ five
猜你喜欢

Transplant DAC chip mcp4725 to nuc980

Dark horse notes - exception handling

百度飞将BMN时序动作定位框架 | 数据准备与训练指南 (上)

The cradle of eternity

域分析工具BloodHound的使用说明

Baidu flying general BMN timing action positioning framework | data preparation and training guide (Part 1)

【信号与系统】

Typical problems of subnet division and super network construction

永久的摇篮

新工作感悟~辞旧迎新~
随机推荐
JS ES5也可以創建常量?
Comparison of picture beds of free white whoring
百度飞将BMN时序动作定位框架 | 数据准备与训练指南 (上)
swiper组件中使用video导致全屏错位
AcWing 1140. Shortest network (minimum spanning tree)
Hutool post requests to set the body parameter to JSON data
uva 1401 dp+Trie
LeetCode:1175. Prime permutation
[signal and system]
Table table setting fillet
New job insights ~ leave the old and welcome the new~
What does front-end processor mean? What is the main function? What is the difference with fortress machine?
Typical problems of subnet division and super network construction
图片打水印 缩放 和一个输入流的转换
场景实践:基于函数计算快速搭建Wordpress博客系统
从零开始匹配vim(0)——vimscript 简介
JVM 内存模型
AcWing 344. 观光之旅题解(floyd求无向图的最小环问题)
AcWing 1142. Busy urban problem solving (minimum spanning tree)
IDEA常用的快捷键