当前位置:网站首页>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
边栏推荐
- 一起看看matlab工具箱内部是如何实现BP神经网络的
- Typical problems of subnet division and super network construction
- 736. LISP syntax parsing: DFS simulation questions
- 字符串的相关编程题
- 场景实践:基于函数计算快速搭建Wordpress博客系统
- Today's question -2022/7/4 modify string reference type variables in lambda body
- 数据手册中的词汇
- AcWing 344. Solution to the problem of sightseeing tour (Floyd finding the minimum ring of undirected graph)
- 制作带照明的DIY焊接排烟器
- 454 Baidu Mianjing 1
猜你喜欢
The difference between Tansig and logsig. Why does BP like to use Tansig
Instructions for using the domain analysis tool bloodhound
Installation of gazebo & connection with ROS
Transplant DAC chip mcp4725 to nuc980
Yunna | work order management software, work order management software app
域分析工具BloodHound的使用说明
今日问题-2022/7/4 lambda体中修改String引用类型变量
According to the analysis of the Internet industry in 2022, how to choose a suitable position?
LeetCode:1175. Prime permutation
场景实践:基于函数计算快速搭建Wordpress博客系统
随机推荐
一文带你走进【内存泄漏】
[advanced C language] 8 written questions of pointer
AcWing 1141. 局域网 题解(kruskalkruskal 求最小生成树)
字符串的相关编程题
Dark horse notes - exception handling
Use nodejs to determine which projects are packaged + released
Match VIM from zero (0) -- Introduction to vimscript
Table table setting fillet
Vocabulary in Data Book
设置Wordpress伪静态连接(无宝塔)
tansig和logsig的差异,为什么BP喜欢用tansig
Baidu flying general BMN timing action positioning framework | data preparation and training guide (Part 2)
Docker method to install MySQL
糊涂工具类(hutool)post请求设置body参数为json数据
DS-5/RVDS4.0变量初始化错误
AcWing 361. 观光奶牛 题解(spfa求正环)
AcWing 1140. 最短网络 (最小生成树)
云呐-工单管理制度及流程,工单管理规范
AcWing 904. 虫洞 题解(spfa求负环)
制作带照明的DIY焊接排烟器