惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
T
Tenable Blog
Project Zero
Project Zero
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
S
Schneier on Security
Scott Helme
Scott Helme
S
Securelist
Know Your Adversary
Know Your Adversary
Vercel News
Vercel News
IT之家
IT之家
V
V2EX
F
Fortinet All Blogs
Simon Willison's Weblog
Simon Willison's Weblog
K
Kaspersky official blog
博客园_首页
T
Tailwind CSS Blog
The GitHub Blog
The GitHub Blog
Spread Privacy
Spread Privacy
Microsoft Security Blog
Microsoft Security Blog
Cisco Talos Blog
Cisco Talos Blog
The Register - Security
The Register - Security
有赞技术团队
有赞技术团队
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
The Hacker News
The Hacker News
L
LINUX DO - 热门话题
Hugging Face - Blog
Hugging Face - Blog
博客园 - 三生石上(FineUI控件)
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
CXSECURITY Database RSS Feed - CXSecurity.com
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Threat Research - Cisco Blogs
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy & Cybersecurity Law Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CERT Recently Published Vulnerability Notes
S
SegmentFault 最新的问题
AWS News Blog
AWS News Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
P
Proofpoint News Feed
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost

博客园 - 消失的风

富文本编辑器vue2-editor实现全屏功能 使用Mist部署Contract到Rinkeby以太坊网络 基于以太坊的Token开发步骤 技术顾问认知(一) Angularjs-项目搭建 Augularjs-起步 appfuse:Excel导出 Appfuse:添加自定义页面组件 基于JQuery实现的文本框自动填充功能 Appfuse:权限控制 Appfuse:记录操作日志 Appfuse:扩展自己的GenericManager Appfuse:第一张表维护 Appfuse:起步 Mybatis基于注解的方式访问数据库 敏捷开发与jira之研发管理模式 敏捷开发与jira之阶段工作项概述 敏捷开发与jira之燃烧图 敏捷开发与jira之流程
JAVA实现图片裁剪
消失的风 · 2015-07-03 · via 博客园 - 消失的风

 1 /**
 2      * 裁剪图片
 3      * @param src 源图片
 4      * @param dest 裁剪后的图片
 5      * @param x    裁剪范围的X坐标
 6      * @param y 裁剪范围的Y坐标
 7      * @param w 裁剪范围的高度
 8      * @param h 裁剪范围的宽度
 9      * @param destW 裁剪后图片的宽度
10      * @param destH 裁剪后图片的高度
11      * @throws IOException
12      */
13     public static void cutImage(String src, String dest, int x, int y, int w,
14             int h,int destW,int destH) throws IOException {
15         try{
16             
17             //未知问题,不知道为啥路径的最后会有\r\n
18             
19             src = src.replace("\r\n", "");
20             dest = dest.replace("\r\n", "");
21             System.out.println("CutImage:src=" + src + ";dest=" + dest + ";x=" + x + ";y=" + y);
22             File file = new File(src);
23             if(file.exists()){
24                 Iterator<ImageReader> iterator = ImageIO.getImageReadersByFormatName("jpg");
25                 ImageReader reader = (ImageReader) iterator.next();
26                 InputStream in = new FileInputStream(src);
27                 ImageInputStream iis = ImageIO.createImageInputStream(in);
28                 reader.setInput(iis, true);
29                 ImageReadParam param = reader.getDefaultReadParam();
30                 Rectangle rect = new Rectangle(x, y, w, h);
31                 param.setSourceRegion(rect);
32                 BufferedImage bi = reader.read(0, param);
33                 if(w != destW){ //被拉伸或者缩小过
34                     bi.flush();
35                     BufferedImage newImage = new BufferedImage(destW,destH,bi.getType());
36                     Graphics g = newImage.getGraphics();
37                     g.drawImage(bi,0,0,destW,destH,null,null);
38                     g.dispose();
39                     ImageIO.write(newImage, "jpg", new File(dest));
40                 }else{
41                     ImageIO.write(bi, "jpg", new File(dest));
42                 }
43                 iis.close();
44                 in.close();
45                 //最后删除临时文件
46                 file.delete();
47             }else{
48                 System.out.println("找不到要裁剪的文件:FileName=" + src);
49             }
50         }catch(Exception ex){
51             ex.printStackTrace();
52         }
53     }

cutImage