等比例压缩图片上传到FTP。有时候会变成黑白图片,是怎么回事?

夜空霓虹 2018-07-06 05:43:17
上传到FTP


public void uploadFtpServer(String filePath, String fileName, String ftpPath) {

logger.info(
"uploadFtpServer(String filePath, String fileName, String ftpPath={}) --start",
filePath, fileName, ftpPath);

FTPClient client = new FTPClient();

int reply = 0;

try {
client.setControlEncoding("GBK");
FTPClientConfig conf = new FTPClientConfig(
FTPClientConfig.SYST_UNIX);
conf.setServerLanguageCode("zh");
client.connect(url, port);
client.login(username, password);

reply = client.getReplyCode();

if (!FTPReply.isPositiveCompletion(reply)) {
client.disconnect();
} else {

if (!client.changeWorkingDirectory(ftpPath)) {
client.makeDirectory(ftpPath);
client.changeWorkingDirectory(ftpPath);
}

client.enterLocalPassiveMode();
client.setFileType(FTPClient.BINARY_FILE_TYPE);
client.setBufferSize(1024 * 1024 * 10);
//client.changeWorkingDirectory(filePath);
//InputStream input = new FileInputStream(new File(filePath));
BufferedInputStream input = new BufferedInputStream(new FileInputStream(new File(filePath)));
// InputStreamReader input = new InputStreamReader(new FileInputStream(new File(filePath)));
client.storeFile(fileName, input);

input.close();
client.logout();
}
} catch (Exception e) {
throw new BaseException(ExceptionCategory.Illegal_Parameter,
"将上传到服务器中的文件读取出来存入ftp文件服务器时出现错误!" + e.getMessage());
} finally {
if (client.isConnected()) {
try {
client.disconnect();
} catch (IOException ioe) {
}
}
logger.info(
"uploadFtpServer(String filePath, String fileName, String ftpPath={}) --end",
filePath, fileName, ftpPath);
}
}


等比例压缩:

public String zipImageFile(File oldFile, File newFile, float rate) {
if (oldFile == null) {
return null;
}
try {
/** 对服务器上的临时文件进行处理 */
Image srcFile = ImageIO.read(oldFile);
int w = srcFile.getWidth(null);
int h = srcFile.getHeight(null);

int height = (int) (h * rate);
int width = (int) (w * rate);

String srcImgPath = newFile.getAbsoluteFile().toString();
String subfix = "jpg";
subfix = srcImgPath.substring(srcImgPath.lastIndexOf(".") + 1,
srcImgPath.length());

BufferedImage buffImg = null;
if (subfix.equals("png")) {
buffImg = new BufferedImage(width, height,
BufferedImage.TYPE_INT_ARGB);
} else {
buffImg = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
}

Graphics2D graphics = buffImg.createGraphics();
graphics.setBackground(new Color(255, 255, 255));
graphics.setColor(new Color(255, 255, 255));
graphics.fillRect(0, 0, width, height);
graphics.drawImage(srcFile.getScaledInstance(width, height,
Image.SCALE_SMOOTH), 0, 0, null);

ImageIO.write(buffImg, subfix, new File(srcImgPath));

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return newFile.getAbsolutePath();
}



...全文
265 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
夜空霓虹 2018-07-06
  • 打赏
  • 举报
回复
而且是不定时出现的。
内容概要:本文围绕基于PI双闭环解耦控制的三相电压型PWM整流器在第四象限运行的仿真研究展开,重点分析其在电流反向流动工况下的控制性能。通过Simulink搭建系统模型,采用电压外环与电流内环构成的双闭环PI控制策略,并引入d-q轴解耦环节以消除交叉耦合影响,实现对整流器在能量回馈状态下的高精度、稳定控制。研究涵盖了系统数学建模、控制器参数设计、解耦算法实现及动态响应仿真验证,充分展示了该控制方法在抑制扰动、提升系统鲁棒性方面的有效性。; 适合人群:电力电子、电气工程及其自动化等相关专业的研究生、科研人员及从事新能源变流器、电能质量治理或工业传动系统开发的工程技术人员;具备自动控制理论基础和Simulink仿真能力者更佳。; 使用场景及目标:①深入掌握三相电压型PWM整流器的工作原理及其在不同运行象限的能量流动特性;②理解并实践PI双闭环控制系统的设计思路与参数整定方法;③学习d-q坐标系下电流解耦控制的实现机制;④熟练运用Simulink进行电力电子系统建模与仿真分析;⑤为实际工程中实现高效能量双向变换提供理论依据与技术参考。; 阅读建议:建议结合Simulink环境同步搭建模型,细致分析各模块的信号流向与控制逻辑,重点关注电流内环的动态跟踪能力和电压外环的稳态调节性能,可通过改变负载突变、电网电压波动等条件进行对比实验,进一步评估系统的抗干扰能力与稳定性表现。

51,408

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧