开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 1.4K

java-utils/DocSys

forked from Rainy/DocSys
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (22)
标签 (21)
master
dev_DocSys_AddGit_Rainy
DocSys_bld_1.18
DocSys_bld_1.15
DocSys_bld_1.16
DocSys_bld_1.14
dev_DocSys_GD_1.13
DocSys_bld_1.13
DocSys_bld_1.12
DocSys_bld_1.11
DocSys_bld_1.10
dev_DocSys_GD
DocSys_bld_1.09
DocSys_bld_1.08
DocSys_bld_1.07
DocSys_bld_1.06
DocSys_bld_1.05
DocSys_bld_1.04
DocSys_bld_1.03
DocSys_bld_1.02
DocSys_V1.17.10
DocSys_V1.17.9
DocSys_V1.17.8
DocSys_V1.17
DocSys_V1.16
DocSys_V1.15
DocSys_V1.14
DocSys_V1.13
DocSys_V1.12
DocSys_V1.11
DocSys_V1.10
DocSys_V1.09
DocSys_V1.08
DocSys_V1.07
DocSys_V1.06
DocSys_V1.05
DocSys_V1.04
DocSys_V1.03
DocSys_V1.02
DocSys_V1.01
master
分支 (22)
标签 (21)
master
dev_DocSys_AddGit_Rainy
DocSys_bld_1.18
DocSys_bld_1.15
DocSys_bld_1.16
DocSys_bld_1.14
dev_DocSys_GD_1.13
DocSys_bld_1.13
DocSys_bld_1.12
DocSys_bld_1.11
DocSys_bld_1.10
dev_DocSys_GD
DocSys_bld_1.09
DocSys_bld_1.08
DocSys_bld_1.07
DocSys_bld_1.06
DocSys_bld_1.05
DocSys_bld_1.04
DocSys_bld_1.03
DocSys_bld_1.02
DocSys_V1.17.10
DocSys_V1.17.9
DocSys_V1.17.8
DocSys_V1.17
DocSys_V1.16
DocSys_V1.15
DocSys_V1.14
DocSys_V1.13
DocSys_V1.12
DocSys_V1.11
DocSys_V1.10
DocSys_V1.09
DocSys_V1.08
DocSys_V1.07
DocSys_V1.06
DocSys_V1.05
DocSys_V1.04
DocSys_V1.03
DocSys_V1.02
DocSys_V1.01
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (22)
标签 (21)
master
dev_DocSys_AddGit_Rainy
DocSys_bld_1.18
DocSys_bld_1.15
DocSys_bld_1.16
DocSys_bld_1.14
dev_DocSys_GD_1.13
DocSys_bld_1.13
DocSys_bld_1.12
DocSys_bld_1.11
DocSys_bld_1.10
dev_DocSys_GD
DocSys_bld_1.09
DocSys_bld_1.08
DocSys_bld_1.07
DocSys_bld_1.06
DocSys_bld_1.05
DocSys_bld_1.04
DocSys_bld_1.03
DocSys_bld_1.02
DocSys_V1.17.10
DocSys_V1.17.9
DocSys_V1.17.8
DocSys_V1.17
DocSys_V1.16
DocSys_V1.15
DocSys_V1.14
DocSys_V1.13
DocSys_V1.12
DocSys_V1.11
DocSys_V1.10
DocSys_V1.09
DocSys_V1.08
DocSys_V1.07
DocSys_V1.06
DocSys_V1.05
DocSys_V1.04
DocSys_V1.03
DocSys_V1.02
DocSys_V1.01
DocSys
/
src
/
util
/
CompressPic.java
DocSys
/
src
/
util
/
CompressPic.java
CompressPic.java 5.36 KB
一键复制 编辑 原始数据 按行查看 历史
zju_rain 提交于 2017年09月28日 11:12 +08:00 . DocSys First Version
package util;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class CompressPic {
/*******************************************************************************
* 缩略图类(通用) 本java类能将jpg、bmp、png、gif图片文件,进行等比或非等比的大小转换。 具体使用方法
* compressPic(大图片路径,生成小图片路径,大图片文件名,生成小图片文名,生成小图片宽度,生成小图片高度,是否等比缩放(默认为true))
*/
private File file = null; // 文件对象
private String inputDir; // 输入图路径
private String outputDir; // 输出图路径
private String inputFileName; // 输入图文件名
private String outputFileName; // 输出图文件名
private int outputWidth = 300; // 默认输出图片宽
private int outputHeight = 300; // 默认输出图片高
private boolean proportion = true; // 是否等比缩放标记(默认为等比缩放)
public CompressPic() { // 初始化变量
inputDir = "";
outputDir = "";
inputFileName = "";
outputFileName = "";
}
public void setInputDir(String inputDir) {
this.inputDir = inputDir;
}
public void setOutputDir(String outputDir) {
this.outputDir = outputDir;
}
public void setInputFileName(String inputFileName) {
this.inputFileName = inputFileName;
}
public void setOutputFileName(String outputFileName) {
this.outputFileName = outputFileName;
}
public void setOutputWidth(int outputWidth) {
this.outputWidth = outputWidth;
}
public void setOutputHeight(int outputHeight) {
this.outputHeight = outputHeight;
}
public void setWidthAndHeight(int width, int height) {
this.outputWidth = width;
this.outputHeight = height;
}
/*
* 获得图片大小 传入参数 String path :图片路径
*/
public long getPicSize(String path) {
file = new File(path);
return file.length();
}
// 图片处理
public String compressPic() {
try {
// 获得源文件
file = new File(inputDir , inputFileName);
//System.out.println(inputDir + inputFileName);
if (!file.exists()) {
// throw new Exception("文件不存在");
file.mkdirs();
System.out.println("文件不存在");
}
Image img = ImageIO.read(file);
// 判断图片格式是否正确
if (img.getWidth(null) == -1) {
System.out.println(" can't read,retry!" + "<BR>");
return "no";
} else {
int newWidth;
int newHeight;
// 判断是否是等比缩放
if (this.proportion == true) {
// 为等比缩放计算输出的图片宽度及高度
double rate1 = ((double) img.getWidth(null))
/ (double) outputWidth + 0.1;
double rate2 = ((double) img.getHeight(null))
/ (double) outputHeight + 0.1;
// 根据缩放比率大的进行缩放控制
double rate = rate1 > rate2 ? rate1 : rate2;
newWidth = (int) (((double) img.getWidth(null)) / rate);
newHeight = (int) (((double) img.getHeight(null)) / rate);
} else {
newWidth = outputWidth; // 输出的图片宽度
newHeight = outputHeight; // 输出的图片高度
}
BufferedImage tag = new BufferedImage((int) newWidth,
(int) newHeight, BufferedImage.TYPE_INT_RGB);
/*
* Image.SCALE_SMOOTH 的缩略算法 生成缩略图片的平滑度的 优先级比速度高 生成的图片质量比较好 但速度慢
*/
tag.getGraphics().drawImage(
img.getScaledInstance(newWidth, newHeight,
Image.SCALE_SMOOTH), 0, 0, null);
File f=new File(outputDir);
if (!f.exists()){
f.mkdirs();
}
f = new File(outputDir,outputFileName);
System.out.println(toString());
// FileOutputStream out = new FileOutputStream(new File(outputDir,outputFileName));
// // JPEGImageEncoder可适用于其他图片类型的转换
// JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
// encoder.encode(tag);
ImageIO.write(tag, "jpeg", new File(outputDir,outputFileName));
tag.flush();
// out.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
return "ok";
}
public String compressPic(String outputDir, String inputFileName,
String outputFileName) {
// 输出图路径
this.outputDir = outputDir;
// 输入图文件名
this.inputFileName = inputFileName;
// 输出图文件名
this.outputFileName = outputFileName;
return compressPic();
}
public String compressPic(String inputDir, String outputDir,
String inputFileName, String outputFileName, int width, int height,
boolean gp) {
// 输入图路径
this.inputDir = inputDir;
// 输出图路径
this.outputDir = outputDir;
// 输入图文件名
this.inputFileName = inputFileName;
// 输出图文件名
this.outputFileName = outputFileName;
// 设置图片长宽
setWidthAndHeight(width, height);
// 是否是等比缩放 标记
this.proportion = gp;
return compressPic();
}
public static void main(String[] args) {
CompressPic cp = new CompressPic();
cp.setInputDir("D:/WWW/pic/");
cp.setOutputDir("D:/WWW/compressPic/");
cp.setInputFileName("freeteam20151030113937_8391.jpg");
cp.setOutputFileName("freeteam20151030113937_8391.jpg");
cp.setOutputHeight(200);
cp.setOutputWidth(300);
cp.compressPic();
}
@Override
public String toString() {
return "输出路径:"+outputDir+",输出名称:"+outputFileName+";w/h:"+outputWidth+"/"+outputHeight;
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

DocSys是基于Java开发的Web文件管理系统,旨在为个人和企业用户提供一个简单、方便、安全的文件存储方案,采用Windows桌面系统和Apple手机的用户操作习惯,支持使用SVN和GIT进行历史版本管理、支持文件加密、支持文件内容全文搜索、支持文件预览、支持文件权限管理、支持用户分组管理,支持扩展和定制。GPL 2.0开源协议.
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/java-utils/DocSys.git
git@gitee.com:java-utils/DocSys.git
java-utils
DocSys
DocSys
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /