当前位置:网站首页>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
边栏推荐
- Transplant DAC chip mcp4725 to nuc980
- Using the entry level of DVA in taro3.*
- grep查找进程时,忽略grep进程本身
- LeetCode:1175. Prime permutation
- THREE. AxesHelper is not a constructor
- Appium自动化测试基础 — uiautomatorviewer定位工具
- 长按按钮执行函数
- 云呐|工单管理软件,工单管理软件APP
- Sword finger offer II 035 Minimum time difference - quick sort plus data conversion
- Amway wave C2 tools
猜你喜欢

AcWing 361. Sightseeing cow problem solution (SPFA seeking positive ring)

设置Wordpress伪静态连接(无宝塔)

Clickhouse fields are grouped and aggregated, and SQL is queried according to the granularity of any time period

405 method not allowed appears when the third party jumps to the website

AcWing 1148. 秘密的牛奶运输 题解(最小生成树)

Instructions for using the domain analysis tool bloodhound

AI automatically generates annotation documents from code

AcWing 345. Cattle station solution (nature and multiplication of Floyd)

刨析《C语言》【进阶】付费知识【完结】

The cradle of eternity
随机推荐
Make Jar, Not War
C language instance_ five
Baidu flying general BMN timing action positioning framework | data preparation and training guide (Part 2)
Spark TPCDS Data Gen
剑指 Offer II 035. 最小时间差-快速排序加数据转换
【信号与系统】
拖拽改变顺序
AcWing 361. Sightseeing cow problem solution (SPFA seeking positive ring)
鼠标右键 自定义
AI automatically generates annotation documents from code
[chip scheme design] pulse oximeter
使用nodejs完成判断哪些项目打包+发版
C语言实例_5
Yunna | work order management software, work order management software app
[signal and system]
增加 pdf 标题浮窗
Telnet,SSH1,SSH2,Telnet/SSL,Rlogin,Serial,TAPI,RAW
dvajs的基础介绍及使用
C language instance_ four
Clickhouse fields are grouped and aggregated, and SQL is queried according to the granularity of any time period