/**
* 圖片基本操作
* @author
*/
public class image_operation_format {
/**
* 縮小并轉(zhuǎn)換格式
*
* @param srcPath
* @param destPath
* @param height
* @param width
* @param formate
* @return
*/
public boolean imageformat(String srcPath, String destPath, int height, int width, String formate) {
boolean flag = false;
try {
File file = new File(srcPath);
File destFile = new File(destPath);
//校驗文件是否存在
if (!destFile.getParentFile().exists()) {
destFile.getParentFile().mkdir();
}
// 讀入文件
BufferedImage src = ImageIO.read(file);
Image image = src.getScaledInstance(width, height, Image.SCALE_DEFAULT);
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = bufferedImage.getGraphics();
// 繪制縮小后的圖
g.drawImage(image, 0, 0, null);
g.dispose();
// 輸出到文件流
flag = ImageIO.write(bufferedImage, formate, new FileOutputStream(destFile));
} catch (IOException e) {
e.printStackTrace();
}
return flag;
}
public static void main(String[] args) {
try {
image_operation_format iof = new image_operation_format();
boolean flag = iof.imageformat("E:\\potos\\原文件\\11.jpg", "E:\\potos\\新文件\\11.png", 400, 400, "png");
System.out.println(flag);
} catch (Exception e) {
System.out.println(e);
}
}
}
圖片轉(zhuǎn)化操作
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。